Solved

Get variable value by name

Posted on 2001-07-12
5
489 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

20 Experts available now in Live!

Get 1:1 Help Now