AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein How to create Eg. Ten instaces of the same form?
Thema durchsuchen
Ansicht
Themen-Optionen

How to create Eg. Ten instaces of the same form?

Ein Thema von pastra · begonnen am 14. Jul 2006 · letzter Beitrag vom 15. Jul 2006
Antwort Antwort
pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#1

How to create Eg. Ten instaces of the same form?

  Alt 14. Jul 2006, 18:38
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..!
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.858 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: How to create Eg. Ten instaces of the same form?

  Alt 14. Jul 2006, 18:42
Delphi-Quellcode:
for i := 1 to 10 do
  with Tform1.Create( self) do
  begin
    Name := 'form1_'+IntToStr( i);
    ...
  end;
Or even better store the Instances into an array.
Markus Kinzler
  Mit Zitat antworten Zitat
Dax
(Gast)

n/a Beiträge
 
#3

Re: How to create Eg. Ten instaces of the same form?

  Alt 14. Jul 2006, 18:45
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:
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;
When done, you can access the Forms through their index
  Mit Zitat antworten Zitat
pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#4

Re: How to create Eg. Ten instaces of the same form?

  Alt 14. Jul 2006, 19:15
Zitat von Dax:
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:
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;
When done, you can access the Forms through their index

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!
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.858 Beiträge
 
Delphi 11 Alexandria
 
#5

Re: How to create Eg. Ten instaces of the same form?

  Alt 14. Jul 2006, 19:17
Have you declared the global Array?
Markus Kinzler
  Mit Zitat antworten Zitat
pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#6

Re: How to create Eg. Ten instaces of the same form?

  Alt 14. Jul 2006, 19:23
Zitat von mkinzler:
Have you declared the global Array?
Sorry for NOT reading therrorly enough what you worte..

Got it working nicely by:

Delphi-Quellcode:
var
  Formz: array[1..10] of TForm1;
(Had to use Z insted og s but that is just a minor detail..


Thank's to all for the fast reply's..


Regards Pastra
  Mit Zitat antworten Zitat
Peinhard

Registriert seit: 8. Jul 2006
152 Beiträge
 
#7

Re: How to create Eg. Ten instaces of the same form?

  Alt 15. Jul 2006, 10:55
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.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz