I have this code:
type
TSolution = record
x1, x2, i1, i2: double;
end;
TSupport = record helper for TSolution
function toFraction: string;
end;
And I would like to be able to call something like this inside (for example) a button click event:
var k: TSolution;
begin
//...
Memo1.Lines.Add(k.x1.toFraction);
//...
end;
Where toFraction is a function I have written that converts a double into a fraction. I think that a record helper is what I need but why doesn't this work?
{ TSupport }
function TSupport.toFraction: string;
begin
Result := TFunction.DoubleToFraction(self);
end;
If you are wondering, TFunction is a class (in the same unit as the record/record helper) and it has the DoubleToFraction class function which returns a string of course.
E2010 Incompatible types: 'Double' and 'TSolution'
Ok this is the error but if I don't use the self then how can I take the parameter? The parameter would be x1, x2, i1 or i2 depending on what I need. In the example above, inside Memo1 I should convert x1 (parameter) to fraction. What to do here?
I have noticed that if you write for example
TSupport = record helper for double
Then the Self works! Basically I would like to know how to avoid the Self to refer to the TSolution record but to its double fields.
TSolutionthat calls your class function. Using helpers here is a complete abuse of the feature. - David Heffernan