Instead of making constructors and doing busy work It would be nice if Free 
Pascal could let you assign records outside of type blocks like:

rec := (x: 0; y: 0; z: 0);

Why isn’t this possible btw? I saw some C++ code do this and it seems like an 
obvious solution that should have existed 20 years ago. The feature exists for 
type blocks so why not just enable it for other parts of code?

I had another idea to make this a little simpler by using open arrays and 
operator overloading. The compiler doesn’t permit this however. Is it a bug, my 
code or just a limitation?

============


type
        TMyRec = record
                x, y, z: integer;
                class operator Explicit(v: array of integer): TMyRec;
        end;

class operator TMyRec.Explicit(v: array of integer): TMyRec;
begin
        result.x := v[0];
        result.y := v[1];
        result.z := v[2];
end;


var
        rec: TMyRec;

rec := TMyRec([1, 2, 3]); // Illegal type conversion: "Set Of Byte" to "TMyRec"

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to