Solved

How to execute a string variable in Delphi?

Posted on 2002-07-04
2
164 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month5 days, 6 hours left to enroll

636 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