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

Reply via email to