Solved

How to execute a string variable in Delphi?

Posted on 2002-07-04
2
154 Views
Last Modified: 2010-04-04
Sample form has 4 edit boxes, is there a way to execute
a string variable? Some code as follows:

var
   i:integer;
   sCommand:string;
begin
  for i:=1 to 3 do
  beging
    sCommand:='edit'+intToStr(i)
         +'.text:='''+intToStr(i)+''';'  
    //execute sCommand;  ?
  end;
end;
0
Comment
Question by:ourselves
2 Comments
 
LVL 5

Accepted Solution

by:
Hamlet081299 earned 50 total points
ID: 7130807
No, there's not.

But there are other ways of doing what you seem to need in this case. Something like...

for i := 0 to ComponentCount - 1 do begin
  if Copy(Components[i].Name, 1, 4) = 'edit' then begin
    (Components[i] as TEdit).Text := Copy(Components[i].Name, 5, 255);
  end;
end;
0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7131423
Object Pascal is a compiled language, it's not interpreted at runtime, so you can't execute code at runtime. You 'll have to write your own interpreter, like Hamlet suggests.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

19 Experts available now in Live!

Get 1:1 Help Now