Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create Tframes on runtime:

is it posible to create runtime frame and add existing panels like setting the parent of panel to the frame? and when it added, dulplicate the frame and use it?

like:

f:= Tframe. create(..)
...

panel3.parent = f; //where panel3 has many controls.

then duplicate the f? was it posible? how? or any other suggerstion? e

like image 400
XBasic3000 Avatar asked Dec 09 '10 13:12

XBasic3000


2 Answers

I don't think you would solve this by duplicating. What you need is a function like this:

function CreateFrameAndHostPanel(Owner: TComponent; Parent: TWinControl; Panel: TPanel): TFrame;
begin
  Result := TFrame.Create(Owner);
  Try
    Result.Parent := Parent;
    Panel.Parent := Result;
  Except
    FreeAndNil(Result);
    raise;  
  End;
end;
like image 65
David Heffernan Avatar answered Oct 26 '22 02:10

David Heffernan


You need to remember that all controls have a parent and an owner. Owners could be nil but then you need to free those controls through code, so most controls are owned by some other component.

Thus, if the owner gets destroyed, the panel would be destroyed too. And if the panel was created in design-time then it's owned by the form that it's on!

Destroying that form would destroy the panel!

But if you create the panels in runtime and set Application as owner instead of a form, they could be moved over multiple forms and frames.

But is it a good design pattern? I don't know what you're trying to do but it's likely a bad idea!

In general, it would be more practical to design the whole frame with panels in design-time. Then add some code that would allow the frame to be created by copying data from another panel or control. That would be a better design pattern...

like image 42
Wim ten Brink Avatar answered Oct 26 '22 01:10

Wim ten Brink