How to use the contents of a string as a variable name lazarus / 61-Beginners ---------------------------------------------------------------------- Jiří Huňáček · 2021-08-13 12:20 Hi, I may have a silly question, but I need to know if it is possible to use the contents of a string as a variable name. For example, as follows Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  VarName: integer;  VarNameStr: string; begin       VarName:=99;       VarNameStr:='VarName';   then I want to write something like WriteLn(VarNameStr); so that the result is 99. Thank you for your help and advice Jirka ---------------------------------------------------------------------- marcov · 2021-08-13 12:22 This is generally not possible in compiled languages. The names are placeholders for human consumption, in the final compiled binary (EXE), they are replaced by addresses. There are some ways around that for special cases, but generally that is more for deep in frameworks usage, and not for own code. And for this specific example there is none. Maybe you have more success if you describe your actual problem rather than what you think you need to solve it. ---------------------------------------------------------------------- lucamar · 2021-08-13 14:53 Quote from: jamie on August 13, 2021, 03:33:44 pmVarnamestr : = inttostr(varname); Does that work for you? That's not what he wants. He wants something like e.g.: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  VarOne: Integer = 999;  VarTwo: Integer = 274; {function ValueFromName(const AVarName: String): Integer;begin  Result := ??????end;} begin    WriteLn(ValueFromName('VarOne'))    WriteLn(ValueFromName('VarTwo'))end. How would you implement ValueFromName()? Remember, the point is that you pass a variable name and return its value. ---------------------------------------------------------------------- Remy Lebeau · 2021-08-13 15:20 In this case, you can use a Dictionary like TFPGMap: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  ..., fgl; var  Dict: TFPGMap;  Value: Integer; begin  Dict := TFPGMap.Create;  try     Dict.Add('VarName', 99);    ...    Value := Dict['VarName'];    ...  finally    Dict.Free;  end;end; Or, if you don't mind storing only strings, a TStringList of 'name=value' pairs will work, too: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  ..., Classes; var  SL: TStringList;  Value: Integer; begin  SL := TStringList.Create;  try     SL.Add('VarName=99');    ...    Value := StrToInt(SL.Values['VarName']);    ...  finally    SL.Free;  end;end; ---------------------------------------------------------------------- engkin · 2021-08-13 17:01 I believe it's doable with custom variant, with usage like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  v:variant;begin  v:=TSomeClass.newInstance;   v.VarOne:=111;  v.VarTwo:=222;   WriteLn(v.FromName('VarOne'));  WriteLn(v.FromName('VarTwo')); ---------------------------------------------------------------------- lucamar · 2021-08-13 18:08 Quote from: engkin on August 13, 2021, 07:01:32 pmI believe it's doable with custom variant, with usage like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {... some code sniped ...}  WriteLn(v.FromName('VarOne'));  WriteLn(v.FromName('VarTwo')); Does that even exists? Or did you take it outa hat? Seriously, if that exists tell us where, please, because it would be almost a treasure trove (at least for me). Oherwise, the same: the question is how would you build such a FromName() function in some (relatively) simple way, without having to resort to building (and populating!) relatively "expensive" classes, as e.g. Remy suggested. Of course, this would be almost ridiculously easy if there were an extensive RTTI framework in place. But AFAICT there isn't (yet?), so .... ---------------------------------------------------------------------- engkin · 2021-08-13 18:20 When you use custom variants the compiler gives you the names and types of properties, methods and their parameters. Let me see if I can produce the simplest example. ---------------------------------------------------------------------- winni · 2021-08-13 18:23 Hi! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Variant.,FromName  is just fantasy. It does not exist. I think we should show a newbie the default ways to code in pascal. And not to follow his crude desires. Winni ---------------------------------------------------------------------- engkin · 2021-08-13 19:05 Quote from: winni on August 13, 2021, 08:23:16 pmis just fantasy. It does not exist. Hi Winni: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program fantasy; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, SysUtils, Variants, fgl  { you can add units after this }; type   TMap=specialize TFPGMap;   TSomeVariantData=record    VarType:tvartype;  end;   { TSomeVariantType }   TSomeVariantType = class(TInvokeableVariantType)  protected    Map:TMap;    procedure DispInvoke(Dest: PVarData; var Source: TVarData;      CallDesc: PCallDesc; Params: Pointer); override;  public    constructor Create; overload;    destructor Destroy; override;    procedure Clear(var V:TVarData);override;    procedure Copy(var Dest:TVarData;const Source:TVarData;      const Indirect:Boolean);override;    { IVarInvokeable }    function DoFunction(var Dest: TVarData; const V: TVarData;      const Name: string; const Arguments: TVarDataArray): Boolean; override;    function DoProcedure(const V: TVarData; const Name: string;      const Arguments: TVarDataArray): Boolean; override;    function GetProperty(var Dest: TVarData; const V: TVarData;      const Name: string): Boolean; override;    function SetProperty(var V: TVarData; const Name: string;      const Value: TVarData): Boolean; override;    function Test:Variant;  end; { TSomeVariantType } procedure TSomeVariantType.DispInvoke(Dest:PVarData;var Source:TVarData;  CallDesc:PCallDesc;Params:Pointer);begin  inherited DispInvoke(Dest,Source,CallDesc,Params);end; constructor TSomeVariantType.Create;begin  inherited Create;  Map:=TMap.Create;end; destructor TSomeVariantType.Destroy;begin  Map.Free;  inherited Destroy;end; procedure TSomeVariantType.Clear(var V:TVarData);begin  FillByte(V,SizeOf(V),0);end; procedure TSomeVariantType.Copy(var Dest:TVarData;const Source:TVarData;  const Indirect:Boolean);begin  Dest.vtype:=Source.vtype;end; function TSomeVariantType.DoFunction(var Dest:TVarData;const V:TVarData;  const Name:string;const Arguments:TVarDataArray):Boolean;var  varName:String;begin  Result:=(Name='ByName') and (Length(Arguments)=1);  if Result then  begin    varName:=VarDataToStr(Arguments[0]);    with Dest do begin      vType := varString;      vString := nil;      AnsiString(vString) := Map[varName];    end;  end;end; function TSomeVariantType.DoProcedure(const V:TVarData;const Name:string;  const Arguments:TVarDataArray):Boolean;begin  Result:=inherited DoProcedure(V,Name,Arguments);end; function TSomeVariantType.GetProperty(var Dest:TVarData;const V:TVarData;  const Name:string):Boolean;begin  Result:=Map.IndexOf(Name)>-1;  if Result then    with Dest do begin      vType := varString;      vString := nil;      AnsiString(vString) := Map[Name];    end;end; function TSomeVariantType.SetProperty(var V:TVarData;const Name:string;  const Value:TVarData):Boolean;begin  Map[Name]:=String(Variant(value));  Result:=True;end; function TSomeVariantType.Test:Variant;begin  tvardata(Result).vtype:=VarType;end; var  m:TSomeVariantType;  v:variant;begin  m:=TSomeVariantType.Create;  v:=m.Test;  WriteLn;   v.VarOne:=111;  v.VarTwo:=222;   WriteLn(v.ByName('VarOne'));  WriteLn(v.ByName('VarTwo'));   WriteLn(v.VarOne);   ReadLn;end. ---------------------------------------------------------------------- mas steindorff · 2021-08-13 19:48 I've used engkin approach successfully  to create list and arrays of values I can access by string . aka i := roomcode['MasterBedrm'].  in my case, I created a unit that also converted integer i  in to the string via a function. another option: I've been looking  at helpers https://wiki.freepascal.org/Helper_types there they show how a helper can get the name of the Tobject.  maybe you can do the same thing as they show for ".ToString" with a helper for a string.  MAS ---------------------------------------------------------------------- howardpc · 2021-08-13 20:37 Without resorting to variants it is also possible to do this sort of thing: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$mode objfpc}{$H+}{$modeswitch duplicatelocals}   function varOne(out Value: String): String;  var    varOne: String = 'variable one';  begin    Value := varOne;    Exit({$I %CurrentRoutine%});  end;   function varTwo(out Value: Word): String;  var    varTwo: Word = $FF33;  begin    Value := varTwo;    Exit({$I %CurrentRoutine%});  end; var  strValue: String;  wordValue: Word; begin  WriteLn('variable ',varOne(strValue),' has the value "',strValue,'"');  WriteLn('variable ',varTwo(wordValue),' has the value ',wordValue);  ReadLn;end. ---------------------------------------------------------------------- 440bx · 2021-08-13 23:28 if he compiles with debug information, using the variable name he could get the address and type of the variable from the debug tables and output the value of the variable using that information. Needless to say, that's a fair amount of work to get the value of a variable using its name, not to mention that it requires debug information. ---------------------------------------------------------------------- dbannon · 2021-08-14 05:00 Quote from: Remy Lebeau on August 13, 2021, 05:20:17 pmIn this case, you can use a Dictionary like TFPGMap: ..... Or, if you don't mind storing only strings, a TStringList of 'name=value' pairs will work, too: ..... Two nice little code snipits Remy, I have added them to the wiki, thanks ! Davo ---------------------------------------------------------------------- devEric69 · 2021-08-14 08:00 Quote from: Jiří Huňáček on August 13, 2021, 02:20:29 pmI need to know if it is possible to use the contents of a string as a variable name. (Thanks to all, for the snipets above ). That said, if @Jiří Huňáček is a newbie, he should first understand that Free Pascal is strongly typed (this is a guarantee of stability at runtime, and it's a guarantee of stability of the control towards the forthcoming complication of the application). Free Pascal is compiled, not interpreted (hence, a speed of execution, as it's as near as possible to the Chip's Assembler language). These are differences to integrate when we come from languages like Python (originally created to be a very good glue, AFAIK), Php (originally created to be a very good html templates manager, AFAIK), Tcl (originally created to be a very good manager for everything, with strings, AFAIK), ... @Jiří Huňáček, you should think first, amho, about transtyping between 2 typed variables first. So, in this context, your question is - in fact - "misplaced" (design problem, or misunderstanding of typing). ---------------------------------------------------------------------- PascalDragon · 2021-08-15 11:35 Quote from: winni on August 13, 2021, 08:23:16 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Variant.,FromName  is just fantasy. It does not exist. It appears you have never used late binding then. For Variants any identifier exists at compile time and it will fail at runtime if the underlying variant can't provide it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program tvarident; {$mode objfpc} uses  SysUtils, Variants; var  v: Variant;  i: LongInt;begin  try    i := v.Foo('Bar');  except    on e: Exception do      Writeln(e.ClassName, ': ', e.Message);  end;end. ---------------------------------------------------------------------- winni · 2021-08-15 12:35 Hi! You showed how to produce an error with variants. But you did not show, how to get Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Variant.FromName to start working Winni ---------------------------------------------------------------------- avk · 2021-08-15 15:27 Mormot uses this approach for example in its TDocVariant. In some minimal form, something similar can be found in my lgVarJson unit. Anyway, this code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test;{$mode objfpc}{$H+}uses  SysUtils, lgVarJson; var  v: Variant; begin  v := VarJsonCreate;  v.Wow := 'Wow';  v.My1001 := 1001;  v.Pi := Pi;  v.False := False;  v.AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything := 42;   WriteLn(v.Wow);  WriteLn(v.My1001);  WriteLn(v.Pi);  WriteLn(v.False);  WriteLn(v.AnswerToTheUltimateQuestionOfLifeTheUnive rseAndEverything);end.  compiles and prints Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Wow10013,14159265358979false42 ---------------------------------------------------------------------- winni · 2021-08-15 16:35 Thanx! And nice that Douglas Adams has now its own constant .... Winni ---------------------------------------------------------------------- avk · 2021-08-15 18:29 Didn't this constant belong to him before? ---------------------------------------------------------------------- dbannon · 2021-08-16 00:16 Quote from: avk on August 15, 2021, 08:29:07 pmDidn't this constant belong to him before? It was not really his, I think it belonged to the mice. Davo ---------------------------------------------------------------------- Blade · 2021-08-16 06:58 Quote from: avk on August 15, 2021, 05:27:41 pmMormot uses this approach for example in its TDocVariant. In some minimal form, something similar can be found in my lgVarJson unit. Interesting, definitely will be playing with this.  https://github.com/avk959/LGenerics ---------------------------------------------------------------------- PascalDragon · 2021-08-16 06:58 Quote from: winni on August 15, 2021, 02:35:54 pmYou showed how to produce an error with variants. But you did not show, how to get Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Variant.FromName to start working Because engkin already showed that earlier. I was merely addressing the point that from the compiler's PoV any identifier exists inside a variant. ---------------------------------------------------------------------- Jiří Huňáček · 2021-08-18 15:37 As marcov wrote, I will give a specific example Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ResetLabelCaptions;var  i: integer;  s: string; begin  for i := 1 to 5 do  begin    s := 'Label' + IntToStr(i);    s.Caption := '';  end;end; this of course doesn't work. I have about 30 labels in the application. I wanted to know if it is possible to make it possible to set it to an empty string in bulk, then fill in just some of them in the same way (I have the data from the database in an array) and I don't want to print it one by one. ---------------------------------------------------------------------- Warfley · 2021-08-18 16:03 Quote from: Jiří Huňáček on August 18, 2021, 05:37:26 pmthis of course doesn't work. I have about 30 labels in the application. I wanted to know if it is possible to make it possible to set it to an empty string in bulk, then fill in just some of them in the same way (I have the data from the database in an array) and I don't want to print it one by one. In this case all you need is a unified addressing mechanism. You can search for components by using FindChildControl in the parent. But this can be quite slow as it uses linear search. Better to build a lookup table, e.g. by using an array: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // as field in your formDataLabels: Array[1..30] of TLabel;...// in form create:for i:=1 to 30 do  DataLabels[i] := LabelParent.FindChildControl('Label' + i.ToString);...// whenever you need to access a label by its number:DataLabels[num].Caption := ...That said, FindChildControl is probably fast enough, considering that updating the UI takes quite a while itself. Compared to that the iteration through the controls should be rather fast PS: You defenetly should give your labels a more meaningful name other then the default name (LabelXX), because otherwise you will soon lose sight about this in your code when you add more labels that are not part of that group ---------------------------------------------------------------------- winni · 2021-08-18 16:31 Hi! Another solution. Requirement is, that the labels are named label1,label2,....label30 We use a set of byte so you can adress Labels up to label255 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   SetOfByte = Set Of Byte;    TForm1 = class(TForm)                      ....                        Label1: TLabel;                        Label2: TLabel;                        ....                        procedure FillLabel(BSet : SetOfByte; s : string);                      ....                         ...  procedure TForm1.FillLabel (BSet : SetOfByte; s : string);var i,k : integer;beginfor i := 0 to ComponentCount -1 do   begin   if (Components[i] is TLabel) then       begin       for k := 0 to 255 do          begin          if k in Bset then             begin             if Components[i].name = 'Label'+IntToStr(k) then                 begin                 Tlabel(Components[i]).caption := s;                 break; // k               end;            end;        end;   end; end;end;  Now you can clear all labels with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FillLabel ([0..255], '');  And you can fill selected Labels with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FillLabel([1,3,7..10], 'A new caption');  Winni ---------------------------------------------------------------------- damieiro · 2021-08-29 13:28 Quote from: Jiří Huňáček on August 18, 2021, 05:37:26 pmAs marcov wrote, I will give a specific example Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ResetLabelCaptions;var  i: integer;  s: string; begin  for i := 1 to 5 do  begin    s := 'Label' + IntToStr(i);    s.Caption := '';  end;end; this of course doesn't work. I have about 30 labels in the application. I wanted to know if it is possible to make it possible to set it to an empty string in bulk, then fill in just some of them in the same way (I have the data from the database in an array) and I don't want to print it one by one. Well, i have been reading all the posts, and i have the sense of killing flies with cannons... I would follow markov way of thinking. Why in the hell would you will need it? Renaming labels seems bad idea with a visual editor and things can be done with meaningful names. And you will have an overloading of some dictionary on all things if needed It seems that the case is that the program will take some text archive or similar to make a "custom" form from file or making some separation between interface designer and code implementation, but with a Lazarus IDE it should not be needed. Other options of use seems some kind of multi-languaje support.. What are this feature needed for? I think this would make a better aproach ---------------------------------------------------------------------- marcov · 2021-08-29 15:03 To load series of components into an array I use: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure loadarray (root:tcomponent;var x : TControlDynArray;basename:string;i1,i2:integer);var l,i : integer;begin l:=i2-i1+1; setlength(x,l); for i := i1 to i2 do   begin     x[i-i1]:=tcontrol(root.FindComponent(basename+inttostr(i)));   end;end; and then use this for e.g. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   labs : array of tlabel; loadarray (self,tcontroldynarray(labs),'Edit',5,14); to load edit5 .. edit14 into an dynamic array with 10 (0..9) elements, which can then be easily FOR()ed. ---------------------------------------------------------------------- bataff · 2023-11-18 18:06 Hello, The subject is interesting. Without the use of a unit or variants, i found two leads : 1. with the enumerated type, because it is possible to rely each argument with a longint (reading by the function ord()) and have the string's name of a argument by a use of typeInfo() (and other things).   But the possibilities by this way is very limited, the longint is only intended to enumerate the arguments of the enum variable ... (too hard/impossible to manipulate the variable). 2. By writing the variable name yourself in the program, or at least the initial name. Indeed, as has already been said in this thread, the compiled program only needs the location of the variable. If, for example, another variable is created with the same address (by 'absolute'), the program cannot know which of the two is at that location. Here's an idea for that (only for byte's type, to start with): - we create a small record like this :Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type bytename = record       v : byte;       name : string; end;- we create a 'bytename''s variable and a byte's variable with the same adresse : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var b : bytename;    v : byte absolute b;v and b.v will be identical (same address) and b.name will be the place provided for the variable name. In this way, you put the name of the variable immediately after it in memory, and then know where the name is if you know the address of the variable (the only thing known about a variable, apart from its content). Looking down this path, here's an example of a program that uses several variables with names to be established at the beginning: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test;Const maxcharname = 10; //maximal number of characters in a variable's name.type bytename = record       v : byte;       name : string[maxcharname];     end;var vn : array[1..5] of bytename;  alpha : byte absolute vn[1];  beta : byte absolute vn[2];  c : byte absolute vn[3];  d : byte absolute vn[4];  e : byte absolute vn[5]; procedure writebytename(var b : byte;s : string); //save the name s of a byte's variable just after this one in memory.var i : byte;begin  if length(s)>0 then begin    pbyte(@b+1)^:=length(s); //write the length of string s in vn[].name[0] (pbyte(@b)^ corresponding to the value of the byte's variable just before).    for i:=1 to length(s) do if i<=maxcharname then pchar(@b+i+1)^:=s[i]; //copy the characters of s in name[1], name[2], ...  end;                                                                                                                                //note : functionning but maybe this code it's too long.end; function readbytename(var b : byte) : string; //return the name of a byte's variable (if saved before by writebytename or else).var i : byte;begin  readbytename:='';  for i:=1 to pbyte(@b+1)^ do if i<=maxcharname then readbytename:=readbytename+pchar(@b+i+1)^; //functionning but maybe this code it's too long.end; BEGIN  alpha:=8; writebytename(alpha,'alpha'); beta:=21; writebytename(beta,'beta'); writebytename(c,'c'); writebytename(d,'d'); writebytename(e,'e');  writeln(readbytename(alpha),' = ',alpha); //output : "alpha = 8"  writeln(readbytename(beta),' = ',beta); //output : "beta = 21"END. Well, there is no need of units but it is more long than simply creating variables, but ... it's fonctionning. ---------------------------------------------------------------------- bataff · 2023-11-18 21:01 Hmm, sorry, I got the subject backwards ... Instead of returning the value of a variable from a string, my program returns a string from the variable. However, I've come up with another idea using enumerated types: - Create an enum with the variable names as arguments. - Create an array of pointers to the variables. - We use the GetEnumValue function (from the typinfo unit), which returns the position of the variable name in the enum, then the array of pointers to find the value of the variable. Here's a simple example I did quickly (still using bytes) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test2;uses typinfo;const maxvar = 50;      //Total number of variables used.type en = (alphaE,betaE,cE,dE,eE); //variable's names as enum's arguments, with a 'E' in the end in order to distinguish them from the true variables.var varname : array[1..maxvar] of pbyte;    alpha,beta,c,d,e : byte;    function readvaluebyte(s : string) : byte; //returns the value of the byte variable whose name is s.var pti : PTypeInfo;begin  pti:=TypeInfo(en);            //note : I don't know if this is how we use a PTypeInfo variable in GetEnumValue, but it works.  readvaluebyte:=varname[GetEnumValue(pti,s+'E')+1]^;end; BEGIN  alpha:=20; beta:=15; c:=8; d:=12; e:=15;  varname[1]:=@alpha; varname[2]:=@beta; varname[3]:=@c; varname[4]:=@d ; varname[5]:=@e; //Initialization of the array of pointers.  writeln('beta = ',readvaluebyte('beta')); //output : 'beta = 15'END.Well, I admit I used a unit, but at least it's simpler!