Solved

Get variable value by name

Posted on 2001-07-12
5
490 Views
Last Modified: 2010-04-06
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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20148966

cheers,
0
Comment
Question by:PeterZG
  • 2
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
CrazyOne earned 10 total points
ID: 6277833
I just did this and it worked for me.

function GetVariableValue(VariableName: variant): variant;
begin
  Result := VariableName;
end;

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

begin
  ABC := 'yes';
  v := GetVariableValue(ABC);
end;


The Crazy One
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 6277841
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 =:)
0
 
LVL 1

Author Comment

by:PeterZG
ID: 6278282
thanks
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6278679
You are welcome. :>)
0
 
LVL 1

Author Comment

by:PeterZG
ID: 6278784
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.

:(
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question