Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

How to execute a string variable in Delphi?

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
ourselves
Asked:
ourselves
1 Solution
 
Hamlet081299Commented:
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
 
herr_apfelschnittCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now