[fpc-pascal] Selecting Records with a variable

James Richters james.richters at productionautomation.net
Sun Dec 20 16:23:15 CET 2020


Thank  you Luca,  that will work much better for me!

James

-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Luca Olivetti via fpc-pascal
Sent: Sunday, December 20, 2020 10:11 AM
To: fpc-pascal at lists.freepascal.org
Cc: Luca Olivetti <luca at ventoso.org>
Subject: Re: [fpc-pascal] Selecting Records with a variable

El 20/12/20 a les 16:02, James Richters via fpc-pascal ha escrit:
> What I’m hopping to accomplish isn't to get it to work... it's to 
> consolidate a whole bunch of functions and procedures that are all exactly the same except for which axis I am working with...
> 
> I have 9 possible Axis, X,Y,Z,W,L.R,A,B,C

....

> ...
> Same thing 7 more times
> ...
> 
> 
> This is a tedious situation.  If I want to change something I have to copy and paste it 9 times then go fix all the variables 9 times.. and it's easy to make a mistake.

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
--
Luca
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list