Create Tframes at runtime:

Is it possible to create a runtime frame and add existing panels, for example, to set the parent element of a panel in a frame? and when he added, duplicate the frame and use it?

as:

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

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

then duplicate f? was it possible? as? or any other suggestion? e

+5
source share
3 answers

I do not think that you would solve this by duplication. You need 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;
+5
source

, . nil, , .

, , . , , !

!

Application , .

? , , , , !

, . , , . ...

+3

You must create a new frame (FRAME2) with the same code that you used to create the first (FRAME1); And later you have to create the whole component included (created at runtime) inside FRAME1 on FRAME2.

To do this, use:

for i := 0 to (FRAME1.ComponentCount - 1) do 
  ...
  cmp := TComponent(FRAME1.Component[i]);
  ... create cmp  on Frame2

You can try the second alternative; Save FRAME1 with TMemoryStream (SaveComponent), and then create a new frame and extract the saved information in Stream (I don't have a test of this option).

Sincerely.

+1
source

All Articles