Xojo Conferences
XDCMay2019MiamiUSA

FB -> RB record Conversion (Real Studio getting started Mailinglist archive)

Back to the thread list
Previous thread: Re: gettingstarted Digest, Vol 11, Issue 17
Next thread: RE: [ANN] InternetPal 1.5.0 Is Now Available


FB -> RB record Conversion   -   Artly There
  Re: FB -> RB record Conversion   -   Joseph J. Strout
   Re: FB -> RB record Conversion   -   Artly There
   Re: FB -> RB record Conversion   -   Artly There
    Re: FB -> RB record Conversion   -   Artly There
     Re: FB -> RB record Conversion   -   Joseph J. Strout
   RE: FB -> RB record Conversion   -   POIDINGER, Michael [JJRAU]

FB -> RB record Conversion
Date: 10.02.05 05:56 (Wed, 9 Feb 2005 23:56:04 -0500)
From: Artly There
Greetings.

I'm wondering what the RB way is to handling records within a record
like the below are handled in Futurebasic...this is a confabulation,
but representative of needed similar structure or equivalent in RB...

In FB these are global.

begin record SmallRec
dim as single rgbfloat[2]
end record

begin record MidRec
dim as SmallRec a, b, c, d, e
end record

begin record BigRec
dim first,last as pointer
dim as single x, y, z, x2, y2 , z2
dim as MidRec Letters
dim as integer Capped
end record

dim gLilPig as BigRec
dim gBigPig(_maxInt) as BigRec // means dynamic array, extendable, via
new pointer.

The original was a linked list and Mac toolbox NewPointer was used to
add a new bigrec here and there with the addresses of each forward and
back in first and last.. In RB I can use a 2 dimensional array though I
think. The element max's are unknown at dim time.

dim gBiggies(-1,-1) as BigRec

Or would this be a property..?

gBiggies(-1,-1) as BigRec

I tried making these as Modules reflecting the hierarchy (1 called
smallrec with property of rgbFloat(2) , one for MidRec with properties
of a, b, c,d,e as SmallRec and on up the chain), but I get errors. As
classes I can class on up the scale, then add the gBiggies(-1,-1) as
BigRecClass, and it will compile. However I'm not sure how that works
as to instancing and "New" needs (if that's needed...I'd like to avoid
that if possible). I had this as classes one time, but got an array
out of bounds error when I tried to access it after filling a field .
At least I thought I filled a field. :)

At this point I've become confused. I'm used to just dimming them once
as a global record like the above in FB and using all over. The User's
Guide talks about dimming arrays in various ways, but only as simple
strings and integers? (if there's a topical topic page I missed in
there for stuff like this, do let me know please) I haven't come across
stuff like this for doing wild things where you need to maintain a lot
of info about the array item in question.

Lastly, in Futurebasic, for such a record as BigRec, one could get the
size in bytes of the actual record by calling SizeOf(BigRec) (size of
array would be Sizeof(bigRec) * elements)

What would one use in RB to get the same information? I see the size
method in Memoryblock class, but that seems to be a bit different.

r
c

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: FB -> RB record Conversion
Date: 10.02.05 15:49 (Thu, 10 Feb 2005 08:49:01 -0600)
From: Joseph J. Strout
At 11:56 PM -0500 2/9/05, Artly There wrote:

>I tried making these as Modules reflecting the hierarchy (1 called
>smallrec with property of rgbFloat(2) , one for MidRec with
>properties of a, b, c,d,e as SmallRec and on up the chain), but I
>get errors.

Yes, a module won't do here; there is only one "instance" of any
given module, and you need something that you can create many of.
So, you need classes.

> As classes I can class on up the scale, then add the
>gBiggies(-1,-1) as BigRecClass, and it will compile. However I'm not
>sure how that works as to instancing and "New" needs (if that's
>needed...I'd like to avoid that if possible).

Why? That's how it works; if you have classes, then you instantiate
them with "New".

> I had this as classes one time, but got an array out of bounds
>error when I tried to access it after filling a field . At least I
>thought I filled a field. :)

Well, no doubt you made a simple mistake -- perhaps your counting was
off by one or some such.

>At this point I've become confused. I'm used to just dimming them
>once as a global record like the above in FB and using all over.

Yes, in RB you declare it as a class once, and use it all over.

> The User's Guide talks about dimming arrays in various ways, but
>only as simple strings and integers?

It's the same with objects. But just as an array of integers is
initialized with all elements set to zero, an array of objects is
initialized with all elements set to nil. To get some different
value into a slot of the array, you assign some different value
(perhaps created with New) to it.

> (if there's a topical topic page I missed in there for stuff like
>this, do let me know please) I haven't come across stuff like this
>for doing wild things where you need to maintain a lot of info about
>the array item in question.

There's nothing wild about that.

>Lastly, in Futurebasic, for such a record as BigRec, one could get
>the size in bytes of the actual record by calling SizeOf(BigRec)
>(size of array would be Sizeof(bigRec) * elements)
>
>What would one use in RB to get the same information?

You don't (and this is a Good Thing). Why do you feel you need it?

Best,
- Joe

Re: FB -> RB record Conversion
Date: 10.02.05 16:40 (Thu, 10 Feb 2005 10:40:15 -0500)
From: Artly There
On Thursday, February 10, 2005, at 09:49 AM, Joseph J. Strout wrote:

> At 11:56 PM -0500 2/9/05, Artly There wrote:
>
>> I tried making these as Modules reflecting the hierarchy (1 called
>> smallrec with property of rgbFloat(2) , one for MidRec with
>> properties of a, b, c,d,e as SmallRec and on up the chain), but I
>> get errors.
>
> Yes, a module won't do here; there is only one "instance" of any given
> module, and you need something that you can create many of. So, you
> need classes.

Gotcha.

>
>> As classes I can class on up the scale, then add the gBiggies(-1,-1)
>> as BigRecClass, and it will compile. However I'm not sure how that
>> works as to instancing and "New" needs (if that's needed...I'd like
>> to avoid that if possible).
>
> Why? That's how it works; if you have classes, then you instantiate
> them with "New".

Just a new way of working is all.

>
>> I had this as classes one time, but got an array out of bounds
>> error when I tried to access it after filling a field . At least I
>> thought I filled a field. :)
>
> Well, no doubt you made a simple mistake -- perhaps your counting was
> off by one or some such.

It was that I'd left it non-expanded I believe.

>
>> At this point I've become confused. I'm used to just dimming them
>> once as a global record like the above in FB and using all over.
>
> Yes, in RB you declare it as a class once, and use it all over.

I'm fathoming this. It's just the object paradigm I think.

>
>> The User's Guide talks about dimming arrays in various ways, but
>> only as simple strings and integers?
>
> It's the same with objects. But just as an array of integers is
> initialized with all elements set to zero, an array of objects is
> initialized with all elements set to nil. To get some different value
> into a slot of the array, you assign some different value (perhaps
> created with New) to it.

Ok.

>
>> (if there's a topical topic page I missed in there for stuff like
>> this, do let me know please) I haven't come across stuff like this
>> for doing wild things where you need to maintain a lot of info about
>> the array item in question.
>
> There's nothing wild about that.

It is when you can't find an example (yet) that's as 'wild' to offer a
template for operating. :) If I'd come across one, I'd not be having to
be coming across as such a big dummy.

>
>> Lastly, in Futurebasic, for such a record as BigRec, one could get
>> the size in bytes of the actual record by calling SizeOf(BigRec)
>> (size of array would be Sizeof(bigRec) * elements)
>>
>> What would one use in RB to get the same information?
>
> You don't (and this is a Good Thing). Why do you feel you need it?

Sizing memoryblocks correctly for manual labor, if ever needed. (future
re-write of a large project where a lot of Ram based work went on)

>
> Best,
> - Joe

Thanks.

Robert

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: FB -> RB record Conversion
Date: 10.02.05 16:42 (Thu, 10 Feb 2005 10:42:58 -0500)
From: Artly There
On Thursday, February 10, 2005, at 12:11 AM, POIDINGER, Michael
[JJRAU] wrote:

>> Greetings.
>>
>> I'm wondering what the RB way is to handling records within a record
>> <snip>

>> begin record SmallRec
>> dim as single rgbfloat[2]
>> end record
>>
> class SmallRec
> property rgbfloat(2) as single

Yep, had that.

>> begin record MidRec
>> dim as SmallRec a, b, c, d, e
>> end record
>>
> class MidRec
> property a as SmallRec
> property b as SmallRec
> ....
> sub Constructor
> a = new SmallRec
> b = new SmallRec
>
> <Snip>

And this Constructor method is created in MidRec methods and is called
automatically?

> Classes are the way to go. It is not clear to me why you need a 2D
> array.
> What's wrong with a 1D array? 1D RB arrays can be dynamically
> enlarged with
> the append method, and redimmed with the redim statement

Here's the setup.

Window1 which is where all the drawing is taking place.
Window1 has a property of DrawEngine as Class MotorWorks, at Window1
event Open this is instanced by DrawEngine = New MotorWorks.

MotorWorks is a class full of drawing and processing methods and such,
and more properties, including Engine(-1) as BigRec

Now, outside of class Motorworks are the 3 Classes just discussed
above, BigRec - > MidRec, and - > SmallRec. The arrows I have there
mean that each class is like a subrecord within the other.

So, there's Class BigRec with several properties, most as singles,
x,y,z, ht and then, say, Carb as MidRec, which contains a lot of
properties a,b,c,d,e as smallrecs. I added a constructor for carb =
New MidRec in the methods of Class BigRec.

I created the other class MidRec and have the properties of and have
added the constructors for a,b,c,d, etc and of course have the class
SmallRec. Super property in all 3 of these record classes points to
<none>

Now, after creating instance DrawEngine in the Window1 Open event and
New, I can Redim(DrawEngine.Engine(100)) and not get an error. If use
uBound after via msgBox it reports 100.

However, and perhaps I am not accessing this correctly via the element
index, I can't say DrawEngine.Engine(1).ht = 1

I get a nil Object exception. So I am wondering where I'm messing this
all up and how to fill up these class-records now? This non-intuitive
way of working is new to me, so I need to be handheld through it.

I'm used to being able to dim a record 1 time in one place, making as
many as I need along the route (fb dynamic array) and just sticking in
the info and getting it back out as so..

Dim dynamic Engine(_maxInt) as BigRec // means dynamic

Engine.ht(index) = 1
Engine.carb.a(index) = cleanburning, love that soybean oil
Engine.a.rgbFloat[1](index) = .439

And so forth. But that land was stripped from me by pestilence, and I
must move into the promised land of RB.

Is there some known RB example somewhere that uses a complex array
record like this, or similar, or better which might show the light?

> and it will compile. However I'm not sure how that works
>> as to instancing and "New" needs (if that's needed...I'd like
>> to avoid
>> that if possible).
>
> Why?

You guys ask a lot of why's. :) Because I'm still ignorant as to how
this all works in places right now. There's a lot I've fathomed, but
all this subclass,, and object and instance stuff..it's a different way
of thinking for someone used to thinking another way for 10 years.

> I had this as classes one time, but got an array
>> out of bounds error when I tried to access it after filling a field .
>> At least I thought I filled a field. :)
>>
> Without code to see what you did, hard to determine the problem, but I
> am
> guessing you left the array as -1,-1 and then tried to put something
> into
> it.

That's what I thought was the likely problem.

>
>> Lastly, in Futurebasic, for such a record as BigRec, one
>> could get the
>> size in bytes of the actual record by calling SizeOf(BigRec) (size of
>> array would be Sizeof(bigRec) * elements)
>
> RB uses references, not pointers, which means accessing memory
> addresses
> cant be done, and memory sizes require some work.
>
> Again, why do you need this?

For feeling more comfortable in RB and for sizing memory blocks to fit
for more esoteric needs up the road.

I am just likely still thinking in terms of my old environs. I'm used
to a) being able to and b) having to , do everything directly via
pointers and addresses in FB.

Thanks very much for your suggestions.

Robert

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: FB -> RB record Conversion
Date: 10.02.05 17:57 (Thu, 10 Feb 2005 11:57:07 -0500)
From: Artly There
Problemo solved.

On Thursday, February 10, 2005, at 10:42 AM, Artly There wrote:

> Window1 which is where all the drawing is taking place.
> Window1 has a property of DrawEngine as Class MotorWorks, at Window1
> event Open this is instanced by DrawEngine = New MotorWorks.
>
> MotorWorks is a class full of drawing and processing methods and such,
> and more properties, including Engine(-1) as BigRec

My confusion and problem was this...

When I added the property of DrawEngine to Window1, and then created
the new instance of that, I assumed that all the related Properties of
Motorworks -were created as New -too-...including that array of classes
Engine() property.

They ain't. :)

Thus...

Even though I could Redim(DrawEngine.Engine(100)) (which I took as
making New Bigrecs automagically) ...I still needed to be saying
after...

DrawEngine.Engine(1) = new BigRec , now go play.

Now it's all working it would seem, and I can access all the sub fields
into the infinity of the record cosmos and get them back out as well.

New feature suggestion : Instant Instance™.

Can go nice with some new Borg Auto-Assimilating Compiler module.

Seriously though, I hope I have this correct now? :)

Thanks for the clarifications and constructor suggestions aid.

Robert

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: FB -> RB record Conversion
Date: 10.02.05 18:26 (Thu, 10 Feb 2005 11:26:22 -0600)
From: Joseph J. Strout
At 11:57 AM -0500 2/10/05, Artly There wrote:

>When I added the property of DrawEngine to
>Window1, and then created the new instance of
>that, I assumed that all the related Properties
>of Motorworks -were created as New
>-too-...including that array of classes Engine()
>property.

They will be, if you tell them to (in the DragEngine constructor).

>Even though I could
>Redim(DrawEngine.Engine(100)) (which I took as
>making New Bigrecs automagically) ...

No, it allocates space for 101 references to
DragEngines. But how does the compiler know what
objects you want these references to refer to?
Maybe you have a good reason to want 101
references to the same object. Or 101 different
objects, which need to be initialized in 101
different ways. Or something else entirely.

Just like, Redim myIntArray(100) does not fill
myIntArray with 101 different numbers that you
may have in mind. It fills it with zeros. In
the same way, an object array is filled with nil;
you can then assign other values as you wish.

I realize that you probably understand all this
now, but I thought it beared restating for others
who may still be confused.

>I still needed to be saying after...
>
>DrawEngine.Engine(1) = new BigRec , now go play.

Right. The compiler can't guess that this is
what you would want; in many cases, it is not.

>New feature suggestion : Instant Instance.

We actually have a feature like that in some
cases (implicit instantiation), but it's not
really a getting-started topic. And it doesn't
make any sense for arrays.

HTH,
- Joe

-

RE: FB -> RB record Conversion
Date: 10.02.05 06:11 (Thu, 10 Feb 2005 16:11:15 +1100)
From: POIDINGER, Michael [JJRAU]
> Greetings.
>
> I'm wondering what the RB way is to handling records within a
> record like the below are handled in Futurebasic...this is a
> confabulation, but representative of needed similar structure
> or equivalent in RB...
>
> In FB these are global.
>
> begin record SmallRec
> dim as single rgbfloat[2]
> end record
>

class SmallRec
property rgbfloat(2) as single

> begin record MidRec
> dim as SmallRec a, b, c, d, e
> end record
>

class MidRec
property a as SmallRec
proerty b as SmallRec
....
sub Constructor
a = new SmallRec
b = new SmallRec
...

> begin record BigRec
> dim first,last as pointer
> dim as single x, y, z, x2, y2 , z2
> dim as MidRec Letters
> dim as integer Capped
> end record
>
> dim gLilPig as BigRec
> dim gBigPig(_maxInt) as BigRec // means dynamic array,
> extendable, via new pointer.
>
> The original was a linked list and Mac toolbox NewPointer was used to
> add a new bigrec here and there with the addresses of each
> forward and
> back in first and last.. In RB I can use a 2 dimensional
> array though I
> think. The element max's are unknown at dim time.
>
> dim gBiggies(-1,-1) as BigRec
>
> Or would this be a property..?
>
> gBiggies(-1,-1) as BigRec
>
> I tried making these as Modules reflecting the hierarchy (1 called
> smallrec with property of rgbFloat(2) , one for MidRec with
> properties
> of a, b, c,d,e as SmallRec and on up the chain), but I get
> errors. As
> classes I can class on up the scale, then add the
> gBiggies(-1,-1) as
> BigRecClass,

Classes are the way to go. It is not clear to me why you need a 2D array.
What's wrong with a 1D array? 1D RB arrays can be dynamically enlarged with
the append method, and redimmed with the redim statement

and it will compile. However I'm not sure how that works
> as to instancing and "New" needs (if that's needed...I'd like
> to avoid
> that if possible).

Why?

I had this as classes one time, but got an array
> out of bounds error when I tried to access it after filling a field .
> At least I thought I filled a field. :)
>

Without code to see what you did, hard to determine the problem, but I am
guessing you left the array as -1,-1 and then tried to put something into
it.

> Lastly, in Futurebasic, for such a record as BigRec, one
> could get the
> size in bytes of the actual record by calling SizeOf(BigRec) (size of
> array would be Sizeof(bigRec) * elements)

RB uses references, not pointers, which means accessing memory addresses
cant be done, and memory sizes require some work.

Again, why do you need this?

Some semantics of your problem would help.

Mike

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>