<div dir="ltr">James, I remember going through some similar motions as you are. Looks like you are searching for a form of indexing your record fields.<div>So many good suggestions, I had to join the fray and try something... My preferred approach would also be an ordinal type for the axes and a record variant, as already suggested. Objects and advanced records would be fine too. That way you get to keep both worlds while evolving your software to a more elegant approach along the lines of some of the suggested solutions.<div>Here is something I tried on top of your example to make sure it actually works.</div><div><br></div><div>program example1;<br><br>Type<br><br>Axis_Name=(anX,anY,anZ,anA,anB,anC);<br>Axis_Array=array[Axis_Name] of Double;<br><br>Axis_Record = Record<br>   X,Y,Z,A,B,C: Double;<br>End;<br><br>Axis_Record_variant = Record<br>   case boolean of<br>     false: (AxRec:Axis_Record);<br>         true:   (AxArr:Axis_Array);<br>End;<br><br>Var<br>AxisValueVar : Axis_Record_variant;<br>AxisValue : Axis_Record absolute AxisValueVar.AxRec;<br><br>//Instead of this:<br>Procedure ShowAxis(Axisletter:Char);<br>Begin<br>   If AxisLetter = 'X' Then<br>      Writeln(AxisValue.X);<br>   If AxisLetter = 'Y' Then<br>      Writeln(AxisValue.Y);<br>   If AxisLetter = 'Z' Then<br>      Writeln(AxisValue.Z);<br>   If AxisLetter = 'A' Then<br>      Writeln(AxisValue.A);<br>   If AxisLetter = 'B' Then<br>      Writeln(AxisValue.B);<br>   If AxisLetter = 'C' Then<br>      Writeln(AxisValue.C);<br>End;<br><br>//I would rather have something like this:<br>Procedure ShowAxisVariant(AxisName:Axis_Name);<br>Begin<br>   Writeln(AxisValueVar.AxArr[AxisName]);<br>End;<br><br>begin<br>  AxisValue.Z := 1234.5678;<br>  ShowAxis('Z');<br> ShowAxisVariant(anZ);<br>end.<br><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 20, 2020 at 2:01 PM James Richters via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Yes, I was trying to keep my data structure, because there were thousands of occurrences ..  <br>
This project has had that structure since Turbo Pascal back in the 80s when it only had 3 axis<br>
It seemed like a good way to have variables all with the same name, and back then it wasn't so bad to have repeated code, <br>
but now I have 9 axis and it's getting ridiculous..  once I realized that Arrays would allow me to simplify things greatly,<br>
it turned out to not be so bad to change it... just a bunch of global search and replaces and a little fixing here and there that actually made it cleaner, <br>
and the whole project has been changed over in a relatively short amount of time... and now I can start consolidating all those functions and procedures.<br>
It was way less work to just change it all to a better structure than it was to work around it.<br>
<br>
James<br>
<br>
>I think this is a typical example where properly thinking about a solution for a programming issue BEFORE going with <br>
>what seems as the logical choice at first glance leads to a much simpler solution without coming up with all kinds of fancy workarounds...<br>
<br>
_______________________________________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div>