Am 31.12.2022 um 04:35 schrieb Hairy Pixels via fpc-pascal:
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 _______________________________________________ fpc-pascal maillist - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
