Solved

Get variable value by name

Posted on 2001-07-12
5
488 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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0
 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
You are welcome. :>)
0
 
LVL 1

Author Comment

by:PeterZG
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now