Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-reference between delphi records

Let's say I have a record TQuaternion and a record TVector. Quaternions have some methods with TVector parameters. On the other hand, TVector supports some operations that have TQuaternion parameters.

Knowing that Delphi (Win32) does not allow for forward record declarations, how do I solve this elegantly?

Using classes is not really an option here, because I really want to use operator overloading for this rare case where it actually makes good sense.

For now I simply moved these particular methods out of the records and into separate functions, the good old-fashioned way. Better suggestions are most welcome.

like image 900
Paul-Jan Avatar asked Oct 25 '25 04:10

Paul-Jan


1 Answers

If the operators are not the actual problem you can solve this using a record helper.

type
  TVector = record
  end;

  TQuaternion = record
    procedure UseVector(var V: TVector);
  end;

  TVectorHelper = record helper for TVector
    procedure UseQuaternion(var Q: TQuaternion);
  end;

This will solve only the circular dependencies and it does not work with operators. It also has the drawback that you cannot have any other record helper for TVector, at least not both of them can be available in the same place.

like image 80
Uwe Raabe Avatar answered Oct 26 '25 22:10

Uwe Raabe