[fpc-pascal] Selecting Records with a variable
Ralf Quint
freedos.la at gmail.com
Sun Dec 20 19:23:33 CET 2020
On 12/20/2020 7:11 AM, Luca Olivetti via fpc-pascal wrote:
>
> Then change your data model.
>
> Instead of
>
> Axis_record = record
> X,Y,Z,A,B,C : Double;
> End;
>
> use
>
> AxisName = (X,Y,Z,A,B,C);
> Axis_record = array[AxisName] of double;
>
> then it's easy to do what you want.
>
> procedure DoSomething(var Axis:Axis_record; const which:AxisName);
> begin
> Axis[which]:=Axis[which]/2;
> end;
>
> Bye
+1
I think this is a typical example where properly thinking about a
solution for a programming issue BEFORE going with what seems as the
logical choice at first glance leads to a much simpler solution without
coming up with all kinds of fancy workarounds...
Ralf
--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the fpc-pascal
mailing list