In my application, I save the component names in a database for use in the future.
In the following example, I want to assign the value of the field from Table1 to the Form1.Parent:
Form1.Parent: = DM.Table1.FieldByName('NOM_PANEL').AsString;
I get the following message:
[dcc32 Error] UPrincipale.pas (794): E2010 Incompatible types: 'TWinControl' and 'string'
I have to convert String to TWinControl.
How please resolve this problem ?
Thank you.
CodePudding user response:
To search for a component by its name, use its Owner's FindComponent()
method, or its Parent's FindChildControl()
method.
For example, let's say you want to assign Form2.Panel1
to Form1.Parent
, and Panel1
is owned by Form2
, and AsString
returns just 'Panel1'
, then you would use:
Form1.Parent := Form2.FindComponent(DM.Table1.FieldByName('NOM_PANEL').AsString) as TWinControl;