I'm a bit uncertain about dynamic arrays as a function result.
If i have this function:function fubar: TStringArray;
begin
SetLength(Result,5);
Result[0]:= 'F*cked';
Result[1]:= 'Up';
Result[2]:= 'Beyond';
Result[3]:= 'All';
Result[4]:= 'Recognition';
end;
then
1) can i use it like: "S:= fubar()[2];" to get 'Beyond', or do I have to assign
the result to an array variable first?
2) Is the memory allocated to the array managed? or do I have to free it
somehow?
If you want to get "F*cked" (pun intended), then yes you can call fubar[0], or fubar[2] to get even "Beyond". AFAIK, it is managed.
I often use construct like "for str in fubar do ...", so it would be bad if the memory wasnt freed. (Or it isnt?)
Lol, shall I congrat?
BTW, since I never used it in such way, was the array initialized?
Yah, thanks, I promoted myself to "Certified Internal Error Hunter"
Initialized.. ":= []" was supposed to be the initialization, of course that doesnt work - hence the error message, but also an internal error.
What I wanted to show you was that if a function returns an array, not as "var/out" but as a result, then you can do "for X in FUNC do ..." which is neat, I do use it often, not only for strings. Code then is more compact, no need to have array variable to store the result.