Board index » delphi » Converting string name to TEdit

Converting string name to TEdit

  Can someone tell me how to convert a string containing
the name of an TEdit to a TEdit?

  Example (doesn't work):

GetEditNo : TEdit;
GetEditNo := 'Edit1';

  I have tried many combinations, but now can only convert
by looping through all TEdits until I find Edit1 and then
get GetEditNo via TEdit(Conponent[i]).

  Thanks.

 

Re:Converting string name to TEdit


GCS <battleRemoveT...@netexecutiveAndThis.com> wrote in
news:Xns91FBC14599BFBbattlegcs@207.218.245.68:

Quote

>   Can someone tell me how to convert a string containing
> the name of an TEdit to a TEdit?

>   Example (doesn't work):

> GetEditNo : TEdit;
> GetEditNo := 'Edit1';

>   I have tried many combinations, but now can only convert
> by looping through all TEdits until I find Edit1 and then
> get GetEditNo via TEdit(Conponent[i]).

>   Thanks.

  I just found this, which will do quite nicely:

var
   Name: String;
   TempEdit: TEdit;
begin
   Name := 'Name1';
   TempEdit := FindComponent(Name);
   if Assigned(TempEdit) then
     TempEdit.Text := 'John';
end;

Other Threads