<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>Well what it’s for, is not just debugging,  I’m trying to manage outputs to ports that are defined by port numbers and pins in an ini file, the ports and pins can really be anything but I need to keep track of the output states of all the pins by specific port value because I can only output all 8 bits of the port at one time.  I can just read back the port and then use AND or OR with what I want and write it back out, but that’s slow, and it also is not necessarily accurate because some ports will give what’s on the pin itself, not what output it is trying to send out… you can be outputting a 1 and the user can force it to 0 and it will read in a 0 now when you write to it,  it’s outputting a 0 and if the user removes the external condition forcing it to 0 it will not go back to 1.. the ports are 1/O ports and are designed to be operated in this manner.   Anyway I made an array of ports and the data each should contain, and then I also have an array of each I/O pin (defined with a string of the name of the variable that holds the pin number) and the port it is looking for…  and then I have procedures and functions that use these arrays to set the stored value of each port correctly, then I just output the entire 8 bits from the storage array.   It’s working well, but I’m tired of doing things like this:<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>               SetStoragePinByName('Ini_Opto_Enable_Positive_Pin', Ini_Opto_Enable_Positive_Pin,True);  Which calls a procedure like this:<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>Procedure SetStoragePinbyname(SSPBN_Var_Name:String; setpinnum:Byte; Pin_State:Boolean);<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>So in quotes I have the name of the variable that contains the name of the variable in the array, so it can figure out the position in the port array, then the actual contents of the actual variable being used… so I know what pin number I am outputting to, and then the state I want to set…   So I have a TON of  exactly what you describe,  calls to functions and procedures with the name of the variable in quotes AND the variable itself.  Variable names are not assigned at runtime, they are pre-defined.  I did not need to use the name of the variable in my pin-list array, but it makes it less confusing if the variable name is what I search for in the array than some kind of cryptic code that would be difficult to maintain.<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>So yes, the only reason to want to do this is so I could hopefully shorted the call to just <o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'>               SetStoragePinByName('Ini_Opto_Enable_Positive_Pin', True) ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'>And it would somehow get the value of 'Ini_Opto_Enable_Positive_Pin'<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>Hmmmm now that I’m typing this all out, I think I can just put the value of the pin in another array also referenced by the same string and then I could make my calls like that.<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>James.<o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='color:windowtext'>From:</span></b><span style='color:windowtext'> fpc-pascal <fpc-pascal-bounces@lists.freepascal.org> <b>On Behalf Of </b>Santiago A.<br><b>Sent:</b> Monday, July 8, 2019 3:40 PM<br><b>To:</b> fpc-pascal@lists.freepascal.org<br><b>Subject:</b> Re: [fpc-pascal] specify variable name with string variable<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>El 07/07/2019 a las 21:58, James Richters escribió:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>This might sound silly,  but is it possible to somehow specify a variable with a string containing the name of the variable?<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>For example:<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Var<o:p></o:p></pre><pre>   MyVariable1 : Word;<o:p></o:p></pre><pre>   MyVariableName : String;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Procedure ShowVariable(Variablename);<o:p></o:p></pre><pre>Begin<o:p></o:p></pre><pre>Writeln(Variablename,' = $', inttohex(    (Somehow get the value of the variable specified by the name here ) ,4));<o:p></o:p></pre><pre>End;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Begin <o:p></o:p></pre><pre>MyVariableName:= 'MyVariable1';<o:p></o:p></pre><pre>ShowVariable(MyVariableName);<o:p></o:p></pre><pre>End.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Is such a thing possible?<o:p></o:p></pre></blockquote><p class=MsoNormal><br>What is it for?<br><br>What about:<o:p></o:p></p><pre>procedure ShowVariable(const Variablename:string; const value:word);<o:p></o:p></pre><pre>begin<o:p></o:p></pre><pre> Writeln(Variablename,' = $'+inttohex(value ,4));<o:p></o:p></pre><pre>end;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>ShowVariable('myVar',myVar);<o:p></o:p></pre><p class=MsoNormal><br>And as far as I understand, you want to call ShowVariable('myVar',myVar), but not wasting time writing the name enclosed in quotes, let the program get the identifier name in runtime, or the other way around, let the program get the value from a name passed in runtime.<br><br>Bad luck, Pascal is not a script language, it is not aware of identifier names in runtime there is no "eval". Thanks to that it gets rids of all the burden of having to keep in runtime structures to know the name, type and value of variable. It generate fast native programs.<br><br>Nevertheless, there are ways, you can program that in Freepascal  using classes, properties, RTII etc. It is more flexible and powerful. But obviously it has a price in complexity. Instead or using the standard operators and reference a simple variable, you must use a more convoluted syntax.<br><br>As far as I see, you don't intend to let the program create new vars in runtime, you just want to write the identifiers of the vars you have hardcoded.  Is it worth? <br><br>(I hope it is not just for debugging)<br><br><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre>Saludos<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Santiago A.<o:p></o:p></pre></div></body></html>