Solved

How to execute a string variable in Delphi?

Posted on 2002-07-04
2
157 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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