Passing array as reference in  SmartMS

Top 

Example code : Passing array as reference in  SmartMS

type

   TFixedSizeArray = array [0..9of Integer;

   TDynamicArray = array of Integer;

 

 

procedure SomeProc(fixed : TFixedSizeArray; dynamic : TDynamicArray);

begin

 fixed[0]   := fixed[0] + 1;

 dynamic.SetLength(20);

 dynamic[0] := fixed[0] + dynamic[0];

end;

 

procedure TForm1.W3Button3Click(Sender: TObject);

var f : TFixedSizeArray;

    d : TDynamicArray;

 

begin

 f[0] := 100;

 d.SetLength(10);

 d[0] := 50;

 

 SomeProc(f, d);

 

 ShowMessage(IntToStr( f[0]) );   //100

 ShowMessage(IntToStr( d[0]) );   //151

end;

Result:

---------------

100 and 151

-------------

Note that f[0] will be unchanged after call SomeProc method! f is a TFixedSizeArray.