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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With