Clone a Delphi Form

Submitted by:Jhon Smith

Date added:08 May, 2012

Category:Delphi

Here shown an example for how to clone a Delphi Form

Tags: delphi form

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