Technical Information Database TI1021D.txt How to use a form several times Category :General Programming Platform :All Product :Delphi All Description: multiple forms Q: I have a form that is a sort of template. I want to be able to create and show the same form several times (with different data in the fields). How do I use the same form several times? A: You need to make modeless window by calling create and show for each form instance, like this: with TMyForm.create(self) do show; To demonstrate how to use and control these new forms, here is an example that changes the caption and name of each form that is created. You have access to it through the form's component array. This example uses an about box (named "box") as the other form. Also, there is a variable called "TheFormCount" that keeps track of how many times the form is instantiated. procedure TForm1.Button1Click(Sender: TObject); begin with TBox.create(self) do begin Name := 'AboutBox_' + intToStr(TheFormCount); caption := 'About Box # ' + intToStr(TheFormCount); Show; end; inc(TheFormCount); end; These forms can be found and used by their name by means of the FindComponent method used something like this: with Form1.FindComponent('AboutBox_' + IntToStr(Something)) as TForm do DoSomethingHere; Reference: 7/16/98 4:33:59 PM
Last Modified: 01-SEP-99