Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Get variable value by name

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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