Hi,
I can't understand casting arrays as method argument. For example, I have this code:
type
TMyArrayOfString = array of string;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
procedure Test(S: TMyArrayOfString);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
const
tmp: array[0..1] of string = ('one', 'two');
begin
//Test(['one', 'two']); <-- this doesn't work
Test(tmp);
end;
procedure TForm1.Test(S: TMyArrayOfString);
begin
end;
Why I can't just call Test(['one', 'two'])? If I call this I get error:
unit1.pas(38,22) Error: Incompatible type for arg no. 1: Got "Array Of Const/Constant Open Array of Constant String", expected "TArrayOfString"
I must declare temporary constant (which is array of string too) and then send it as argument. If argument is type "array of string" instead of TMyArrayOfString then is ok. Why compilator is so sensitive in this case?
Regards