![]() |
How to create Eg. Ten instaces of the same form?
Hi I would like to know how to create 10 forms, all created from "Form1"
The forms need to be active at the same time so uniqe names are required.. How to acomplice that? Thanks..! |
Re: How to create Eg. Ten instaces of the same form?
Delphi-Quellcode:
Or even better store the Instances into an array.
for i := 1 to 10 do
with Tform1.Create( self) do begin Name := 'form1_'+IntToStr( i); ... end; |
Re: How to create Eg. Ten instaces of the same form?
Well, first: do not use the global var Form1 in the Form's Unit anymore. Rather use self when you are in the same Unit. If you want to use these Forms from other Forms or Units, you must create a new global var of type array[1..10] of TForm1 to hold the ten Forms for access from outside themselves.
After that, you need an activation-procedure to create an show all the Forms, maybe like this:
Delphi-Quellcode:
When done, you can access the Forms through their index :)
procedure ShowAllForms;
var i: Integer; begin for i := 1 to 10 do begin Forms[i] := TForm1.Create(Application); // Forms is your array Forms[i].Show; end; end; |
Re: How to create Eg. Ten instaces of the same form?
Zitat:
Okay this code look interresting... When trying to compile in (D6) i get: '.' expected but [ found at: Forms[ What am I dooing wrong? Do I need to define some unit in the USES clase? Creers! |
Re: How to create Eg. Ten instaces of the same form?
Have you declared the global Array?
|
Re: How to create Eg. Ten instaces of the same form?
Zitat:
Got it working nicely by:
Delphi-Quellcode:
(Had to use Z insted og s but that is just a minor detail..
var
Formz: array[1..10] of TForm1; Thank's to all for the fast reply's.. Regards Pastra |
Re: How to create Eg. Ten instaces of the same form?
A TList or TObjectList is also an appropriate place to store the form instances. And how about a little component that manages most of the tasks involved with that - eg showing forms with certain contents or bring them to front, destroy forms when the calling form ist destroyed or dynamically build a 'Windows' menu on that form etc.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:32 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz