[fpc-pascal] specify variable name with string variable
james at productionautomation.net
Mon Jul 8 12:47:56 CEST 2019
Thank you for the answer and the example... I didn't know there was such a thing as a variable dictionary, but It looks like that may work for me, I'll give it a try!
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of zh loza
Sent: Sunday, July 7, 2019 4:34 PM
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Subject: Re: [fpc-pascal] specify variable name with string variable
Hi all! It's my first answer to the mailing list, hopefully I won't screw anything up.
On Sun, Jul 7, 2019 at 10:58 PM James Richters <james at productionautomation.net> wrote:
> This might sound silly, but is it possible to somehow specify a variable with a string containing the name of the variable?
You might want to try using generic dictionaries. E.g. like this:
TVariableDictionary = specialize TDictionary<String, PWord>;
MyDictionary := TVariableDictionary.Create;
MyDictionary['MyVariable1']^ := 100;
If you need to address variables of different type, try Variants ( https://wiki.freepascal.org/Variant ).
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