Search code examples
delphidelphi-10.4-sydney

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


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 ...


Solution

  • 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?