2

I would like to implement 2 record structures with imlicit type casts:

  TMyRecord1=record
    X, Y: Integer;
    //other fields specific to TMyRecord1
    class operator Implicit(const Rec: TMyRecord2): TMyRecord1; //<- problem: TMyRecord2 undeclared
  end;

  TMyRecord2=record
    X, Y: Real;
    //other fields specific to TMyRecord2
    class operator Implicit(const Rec: TMyRecord1): TMyRecord2;
  end;

  class operator TMyRecord1.Implicit(const Rec: TMyRecord2): TMyRecord1;
  begin
    Result.X:=Round(Rec.X);
    Result.Y:=Round(Rec.Y);
  end;

  class operator TMyRecord2.Implicit(const Rec: TMyRecord1): TMyRecord2;
  begin
    Result.X:=Rec.X;
    Result.Y:=Rec.Y;
  end;

The problem is the circular reference.

What is the best way to implement this?

user3384674
  • 759
  • 8
  • 28

0 Answers0