Doing a SetLength on an array passed into a proc by reference

Posted by csharpdefector on Stack Overflow See other posts from Stack Overflow or by csharpdefector
Published on 2010-05-23T01:35:14Z Indexed on 2010/05/23 1:40 UTC
Read the original article Hit count: 219

Filed under:

Hi All,

Sure, even I can do this...

var
  testarray : array of string;

setlength(testarray, 5);

but if I want to get clever and have a procedure into which I pass the array by referance like this I cant do it!

procedure DoStuffWithArray(var passedarray : array of string);
begin
  setlength(passedarray, 5);
end;

compiler says 'incompatible types' on the single line of code in my proc.

I can do other stuff on the array like set set element values if i do a setlength before i call the proc, but I cannot do the setlength in my proc, which is what I want to do.

Any help much appreciated, thanks all.

© Stack Overflow or respective owner

Related posts about delphi