[fpc-pascal] Selecting Records with a variable
Jean SUZINEAU
jean.suzineau at wanadoo.fr
Sun Dec 20 05:26:10 CET 2020
I know you don't like objects, but maybe something like :
====================================================
unit uAxisRecord;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
{ TAxisRecord }
TAxisRecord
=
object
X,Y,Z,A,B,C: Double;
function Value_from_Letter( _Axisletter:Char): double;
procedure ShowAxis( _Axisletter:Char);
end;
implementation
{ TAxisRecord }
function TAxisRecord.Value_from_Letter(_Axisletter: Char): double;
begin
case _Axisletter
of
'X': Result:= X;
'Y': Result:= Y;
'Z': Result:= Z;
'A': Result:= A;
'B': Result:= B;
'C': Result:= C;
else Result:= X;//or throw an exception
end;
end;
procedure TAxisRecord.ShowAxis(_Axisletter: Char);
begin
WriteLn( Value_from_Letter( _Axisletter));
end;
end.
==========================================
And then where you need it:
...
uses uAxisRecord
...
Var
AxisValue : TAxisRecord;
...
Procedure ShowAxis(Axisletter:Char);
Begin
Writeln(AxisValue.Value_from_Letter( Axisletter);
End;
or just:
AxisValue.ShowAxis('X');
"object" works as "record", no need to allocate or call a constructor,
but you can define methods on it.
(I didn't test but it should work)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20201220/5b2424a4/attachment.htm>
More information about the fpc-pascal
mailing list