Link to home
Start Free TrialLog in
Avatar of PeterZG
PeterZG

asked on

Get variable value by name

Is there any way to get value of variable by having name of this variable? Something like:
function GetVariableValue(VariableName: string): variant

Sorry for 10 points only, but it's all I have at the moment.

BTW: please look at
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20148966

cheers,
ASKER CERTIFIED SOLUTION
Avatar of CrazyOne
CrazyOne
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheNeil
TheNeil

You could certainly do it for components but for variables then the only way would be to access the original source code. Going with the component approach:

PROCEDURE FindObjectType(sName : STRING);
VAR
  iCount : LONGINT;
BEGIN
  FOR iCount := 0 TO (ComponentCount - 1)
  DO
    IF Components[iCount].Name = sName
    THEN
      ShowMessage(Components[iCount].ClassName);
END;

Probably not what you were after but it demonstrates how to search for the component (by name) and extract some information from it

The Neil =:)
Avatar of PeterZG

ASKER

thanks
You are welcome. :>)
Avatar of PeterZG

ASKER

Ha!
Just checked correctly and it didn't work.
for example, leaving the function as it is and modifying procedure to:

procedure TForm1.Button1Click(Sender: TObject);
var
 ABC: string;
 v: Variant;

begin
 v := GetVariableValue(Edit1.Text);
end;


it gives what was typed in Edit1 and not value of variable specified in Edit1.

:(