Solved

How to execute a string variable in Delphi?

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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