Thanx for that link rob...very nice!

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: Wednesday, March 08, 2006 10:52 AM
To: Borland's Delphi Discussion List
Subject: Re: Objects and Lists...addendum -> Strings

Robert Meek wrote:
> One of the points I was trying to make was that dynamic Arrays are
> unlike ansi strings in the sense that with the latter Delphi handles the
> allocation for you.  It's a no-brainer.  I can use the same string var
over
> and over no matter what the number of chars are that I need to stuff into
> it.  With dynamic arrays, this isn't true.

Yes it is.

> You have to call
> SetLength(array, Integer) every time you want to assign a new element to
it.

You're still using the same variable over and over.

And you don't *have* to call Setlength every time. You can call it once 
at the beginning with a large amount and then fill in that space as you 
proceed. Just like setting the length of a string, or the Capacity 
property of a list.

> At the same time, the array itself is typed so you can't use it to hold
more
> than one element type AND it automatically deallocates memory if you
delete
> an element!

The only way to delete an element is to use SetLength to truncate the 
array. If SetLength doesn't count as automatic handling of allocation, 
then it doesn't count as automatic handling of deallocation, either. 
Please see my article on how to delete elements from dynamic arrays:

http://www.cs.wisc.edu/~rkennedy/array-delete

-- 
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

Reply via email to