There's no difference between any of these methods at all that I can
see, however just to prevent confusion I prefer using SetLength, I only use
nil with objects, and its possible someone could misread delete and think
the object itself is being deleted.
Regarding MyArray[0].Create(aOwner); I see that now but from the way
Delphi syntax is it seems as if you should be able to create the object and
add it to the array in one step.
from Robert Meek dba Tangentals Design CCopyright 2006
"When I examine myself and my methods of thought, I come to the conclusion
that the gift of Fantasy has meant more to me then my talent for absorbing
positive knowledge!"
Albert Einstein
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Rob Kennedy
Sent: Sunday, March 05, 2006 9:03 PM
To: Borland's Delphi Discussion List
Subject: Re: Objects and Lists...addendum
Robert Meek wrote:
> You confirmed what I thought. From what I've been able to find out,
> there are three ways to end the life of a dynamic array. The first is to
> delete it's last element, ( I was calling them fields before...sorry ), in
> which case Delphi will dispose of it because it's reference count goes to
> zero. The second, by setting it to nil. And the third by
setlength(array,
> 0).
What's the difference between deleting the last element and setting the
length to zero?
> I knew that an Array isn't a TComponent descendant but what struck
> me as strange is that CodeInsight shows I can do this:
> MyArrayofTComponents[0].Create()
That's taking the first element of the array, which is a value of type
TComponent, and calling the Create method on that component.
MyArrayOfTComponents is an array. MyArrayOfTComponents[0] is a
TComponent reference within that array.
> and asks for an Owner where the Array is
> one of a set of TComponent. What is it attempting to create here? I
> thought perhaps it was a shortcut to creating an element of the type but
> though it compiles fine I get an AV as soon as I attempt to access one of
> the element properties!
You get an exception for the same reason you'd get an exception here:
var
x: TComponent;
begin
x.Create(nil);
end;
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi