Hairy Pixels wrote 20 lines
Why is using the open array parameter illegal using the Object type?
========================
{$mode objfpc}
program test;
type
TMyObject = object
constructor Create(text: array of String);
end;
constructor TMyObject.Create(text: array of String);
begin
end;
begin
TMyObject.Create(['1', '2', '3']); // error: Illegal expression
end.
Objects are not classes, they don't know the Object Pascal style syntax for creating them, instead you need to use the syntax for objects from TP times:
=== code begin ===
program tobj;
type
TMyObject = object
constructor Create(text: array of String);
destructor Destroy;
end;
PMyObject = ^TMyObject;
constructor TMyObject.Create(text: array of String);
begin
Writeln(Length(text));
end;
destructor TMyObject.Destroy;
begin
end;
var
o: PMyObject;
begin
New(o, Create(['1', '2', '3']));
Dispose(o, Destroy);
end.
=== code end ===
Regards,
Sven