[fpc-pascal] specify variable name with string variable

Santiago A. svaa at ciberpiula.net
Tue Jul 9 10:09:08 CEST 2019


El 08/07/2019 a las 22:43, James Richters escribió:
>
> ports that are defined by port numbers and pins in an ini file,
>
Well, then they are dynamic. They are not hardcoded.

I would use something like:

TPortIdentifier=(Pin_1, pin_2, Port_x, Port_y...);

TIOPort=object
        private
           FPortPin:boolean;
           FPortByte:boolean;
           procedure SetPortPin(value:boolean);
           procedure SetPortByte(value:byte);
        public

           OtherData:...  // pin, port etc or other data

           PortAdress:PWord; // pointer to memory

           Name:string;
           constructor Init(aName:name;aPword:pWord);
           property  PortPin:boolean read fPortPin write SetPortPin;

           property  PortByte:byte read fPortByte write SetPortByte;
         end;

   TPortList=array[TPortIdentifier] of TIOPort;

var
  PortList:TPortList;

begin
   // fill the array with name and values from Ini file
    PorList[Pin_1].init('Pin-1', at xxxx);
    PorList[Pin_2].init('Pin-2', at xxxx);

   // call
   PortList[pin_1].PortPin:=true;
   PortList[pin_2].PortPin:=false;
end.


Or you can use a TFPGMap from the standard library fgl.

-- 
Saludos

Santiago A.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190709/8ba729b6/attachment.html>


More information about the fpc-pascal mailing list