> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Robert Meek
> Sent: Saturday, March 04, 2006 1:00 PM
> To: 'Borland's Delphi Discussion List'
> Subject: RE: Objects and Lists...addendum
> 
>       In regards to the previous question below, some years ago when I
> first started learning Delphi, I had an interesting conversation with
> Cosmin
> right here about the various ways one could setup an editor for multiple
> pages/files.

Some years ago? Have I been a member for that long?

>       So if I create an array is ii okay to set its length at the start to
> just 1?  I tried it and it compiles and runs okay but I wondered if there
> might be something else that would make doing so a bad idea?

Nothing wrong with 1. You may set it up to whatever works for you.

>       Now when I need to create a new page in the editor, I first create
> the new tab, then a new instance of the object type I wrote, and then I
> call
> SetLength and increment its current length to hold another object, and
> finally I assign the object to the array.  All this I've tested and it
> works
> great but it's freeing the resources used I'm not so sure about.
>       When I'm ready to close the editor, I must first free and nil each
> instance of my object that I had created at runtime, correct?  But what if
> when I create each object I set the form as the object's owner?  Would
> they
> then be freed like any other component when the form itself is freed?

I wasn't able to follow. What objects are you creating at runtime? The ones
that go into the array? Did you go for objects or records? If you did go for
records they can't be freed as they're not objects!

> What
> about making the object's owner the array itself?  Is this possible and
> would there be any advantage or disadvantage to doing so?  And finally, is

If by Object you mean TObject then you can't set it's owner because it
doesn't have one. It is the TComponent class that introduces. Alo
TComponent's owner must itself be an TComponent. Arrays are not TComponent
descendent so they can't be used as the owner for an TComponent descendent.

> And finally, is it true that no matter how many fields an array might
> contain, simply
> setting the array to nil will free it properly, or do I have to iterate
> thru
> and delete each field first?  Is there anyway, like with an ObjectList, to
> make the array responsible for the objects it references?

When I need to "free" an array I usually do SetLength(array,0); I don't know
if this is equivalent to assigning it nil.

About making it responsable for it's content:

The array can't be smarten up. TObjectList can be made smart because it has
a destructor. The only smart thing the array would be to Dispose()
everything. This means you can safely have strings in the array as the
memory allocated for those would be freed. It will not free objects.

Everything I've sad is true for Win32 Delphi. Don't know enough about dot
net!

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to