Delphi: how to get exact name of component with TEdit text

155 Views Asked by At

Sorry, maybe I couldn't formulate my question clearly. I have a lot of Tpanels in my form. I need get exact name of a TPanel with TEdit.text. for example TEdit.text is 26, instead of using if panel26.color=clred then ..., I want if (Panel+edit1.text).color=clred then ...

1

There are 1 best solutions below

4
On BEST ANSWER

You can use FindComponent like this:

var
  TmpPanel: TPanel;
begin
  TmpPanel := FindComponent('Panel' + edit1.text) as TPanel;
  if TmpPanel <> nil then      // We found it
    if TmpPanel.color=clred then ...
end;

source for my answer if you want to dig deeper : How can I refer to a control whose name is determined at runtime?