Reputation: 244
I'm trying to use assign on a TPanel
configured in the designer but it doesn't work.
var
LPanel : TPanel;
begin
LPanel := TPanel.Create(nil);
LPanel.Assign(Panel1); // Panel1 is a panel made in the form designer
end;
The error message is something like "TPanel cannot be assigned to TPanel." (I have the german version of RAD Studio... The exact error message on german is "TPanel kann nicht zu TPanel zugewiesen werden.")
I designed a TPanel with other components in it using the Form Designer. Now I want to add new TPanel
instances to a TLayout which should be the same as the TPanel I want to assign from, including all child controls.
Upvotes: 2
Views: 388
Reputation: 595305
Most VCL and FMX components, including TPanel
, DO NOT implement Assign()
at all. Typically only utility classes that are used for component properties implement Assign()
for use in their property setters.
For what you are attempting, you should use a Frame instead of TPanel
. You can design a Frame at design-time, just like a Form or DataModule, and then create instances of it at run-time as needed.
See Embarcadero's documentation for more details:
Upvotes: 3
Reputation: 14832
Unfortunately I don't currently have access to Delphi to confirm. But it seems Assign
ing TPanel
is deliberately blocked by the framework.
That said, what you're trying to achieve seems more appropriately handled with TFrame
Once you've created your frame, you should be able to use the following code to create a new instance at run-time.
uses
...
frMyFrame;
...
var
LNewFrame : TFrame;
begin
LNewFrame := TMyFrame.Create(nil); //Are you sure you don't want to assign an owner?
LNewFrame.Parent := Self; //Assuming you want to position the frame directly on the form
//Otherwise you could place it on a simple panel.
//Set attributes for positioning
//Don't forget resource management (see ownership comment)
...
end;
Upvotes: 2