sure, but you end up with a separate dictionary for each type. Or, you
can try variants, as originally suggested, but then you need to declare
all your variables as a Variant type.
uses fgl, variants;
type
TVariableDictionary = specialize TFPGMap<String, PVariant>;
On 7/8/19 11:20 AM, James Richters wrote:
Thank you, using fgl; did work.
Am I correct in assuming that if I want other types of Variables I would change
PWord in
specialize TFPGMap<String, PWord>;
to something else, maybe PString, PDouble, PLongint.... etc?
James
-----Original Message-----
From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> On Behalf Of Stefan
V. Pantazi
Sent: Monday, July 8, 2019 10:54 AM
To: fpc-pascal@lists.freepascal.org
Subject: Re: [fpc-pascal] specify variable name with string variable
You can use the TFPGMap class in fgl unit to implement the dictionary.
fgl should be available in 3.0.4. Try to replace the Generics.Collections with
fgl and the type definition in the example code from zh loza. The rest should
be identical.
[...]
uses fgl;
type
TVariableDictionary = specialize TFPGMap<String, PWord>;
[...]
On 7/8/19 8:09 AM, James Richters wrote:
I'm on windows....
Generics.Collections seems to be something that was added after 3.0.4, I've
downloaded the current FPC source code, but I’m not sure how to build it.. can
someone point me in the right direction on how to compile the current source
code?
James
-----Original Message-----
From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> On Behalf
Of James Richters
Sent: Monday, July 8, 2019 6:48 AM
To: 'FPC-Pascal users discussions' <fpc-pascal@lists.freepascal.org>
Subject: Re: [fpc-pascal] specify variable name with string variable
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!
James
-----Original Message-----
From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> On Behalf
Of zh loza
Sent: Sunday, July 7, 2019 4:34 PM
To: FPC-Pascal users discussions <fpc-pascal@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 <ja...@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:
program Project1;
uses
SysUtils, Generics.Collections;
type
TVariableDictionary = specialize TDictionary<String, PWord>;
var
MyDictionary: TVariableDictionary;
MyVariable1: Word;
begin
MyDictionary := TVariableDictionary.Create;
MyDictionary.Add('MyVariable1', @MyVariable1);
MyDictionary['MyVariable1']^ := 100;
WriteLn(MyVariable1);
WriteLn(MyDictionary['MyVariable1']^);
FreeAndNil(MyDictionary);
end.
If you need to address variables of different type, try Variants (
https://wiki.freepascal.org/Variant ).
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
--
_______________________________________________________
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
--
_______________________________________________________
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal