[fpc-pascal] Selecting Records with a variable

James Richters james.richters at productionautomation.net
Sun Dec 20 01:16:12 CET 2020


The best way to explain what I'm hoping to do is by example... 
Say I have this record:

Type
Axis_Record = Record
   X,Y,Z,A,B,C    : Double;
End;

Var
AxisValue : Axis_Record;

Instead of this:  

Procedure ShowAxis(Axisletter:Char);
Begin
   If AxisLetter = 'X' Then
      Writeln(AxisValue.X);
   If AxisLetter = 'Y' Then
      Writeln(AxisValue.Y);
   If AxisLetter = 'Z' Then
      Writeln(AxisValue.Z);
   If AxisLetter = 'A' Then
      Writeln(AxisValue.A);
   If AxisLetter = 'B' Then
      Writeln(AxisValue.B);
   If AxisLetter = 'C' Then
      Writeln(AxisValue.C);
End;

I would rather have something like this:

Procedure ShowAxis(Axisletter:Char);
Begin
   Writeln(AxisValue.AxisLetter);
End;

Is there some syntax that would work to select the correct record based on the variable so I can avoid having all the If statements?



James



More information about the fpc-pascal mailing list