[fpc-pascal] Re: More fun with dynamic arrays

leledumbo leledumbo_cool at yahoo.co.id
Sat Nov 19 18:15:46 CET 2011


> It seems a bit drastic to me to discard the existence of the dynamic array 
as well as the (non-existent) values stored in it! Presumably, all will be
well 
if I size the array inside the initializing routine, breaking my rule that
the 
routine that makes the array must also contain the code to get rid of it. 

Essentially, dynamic arrays are just pointers. If you intend to create
something to initialize it, better use function that returns the initialized
array. e.g.:

function Init(const N: LongInt): DataA;
begin
  SetLength(Result,N);
  ... // initialize Result
end;

you can then simply:

var
  a: DataA;
begin
  ...
  a := Init(N);
  ...
end.

> That is a distinction too subtle for me!

I agree, but this is how Borland designed the language, in which we follow
for compatibility reason.

--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/More-fun-with-dynamic-arrays-tp5002872p5007151.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list