How to Clone a Delphi Form

Submitted by:Andery Smith

Date added:15 June, 2013

Category:Delphi

Example shows here How to Clone a Delphi Form.
Note: when you create a new clone from an existing form, the clone's OnCreate will not execute.

Tags: delphi form , clone

Code Snippet:

 procedure FormClone(form : TForm) ;
var
ms : TMemoryStream;
clone : TForm;
begin
ms := TMemoryStream.Create;
try
ms.WriteComponent(form) ;
ms.Position := 0;
clone := TFormClass(form.ClassType).CreateNew(Application) ;
ms.ReadComponent(clone) ;

clone.Left := form.Left + 10;
clone.Top := form.Top + 10;
clone.Show;
finally
ms.Free;
end;
end;


//Usage procedure TForm1.Button1Click(Sender: TObject) ; begin FormClone(Form1) ; end;
 
 

Comments