Is there a way to make something like this work?
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
type
TMyRecord = record
class operator Explicit(const a: array of integer): TMyRecord;
end;
{ TMyRecord }
class operator TMyRecord.Explicit(const a: array of integer): TMyRecord;
begin
end;
var
a: array[0..100] of integer;
begin
TMyRecord(a); //Incompatible types: 'array of Integer' and 'array[0..100] of Integer
end.
“TMyRecord.Explicit(const a: TIntegerDynArray)” works for TIntegerDynArray, but I can’t get static arrays to work.
I’d say that is a compiler bug/limitation and that you have no way around it.
I tried using
Slicelike this:which results in this compiler error:
So the compiler doesn’t recognise that the explicit operator is expecting an open array parameter.
A plain method call rather than an operator is fine which further leads me to believe that the compiler is simply not going to play ball.
If you can’t use open arrays then there is no clean way out for you.