Autor Beitrag
LittleBen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Sa 04.12.10 11:06 
Hallo Zusammen,

irgendwie stehe ich gerade auf dem Schlauch. Mir fällt einfach nicht ein wie ich es anstellen soll:
Ich möchte 10 x Form2 kreieren, aber jede unterscheiden.
Also:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
begin
 Form2:= Form2.Create(Self);
 Form2.Show;
end;


Wenn ich dies nun 10 mal ausführe, dann entsteht 10 x Form2(logisch).
Wenn ich nun den Namen der Form beim aufrufen in einer MessageBox anzeigen lass, dann kommt dies bei raus:
Form2
Form2_1
Form2_2
Form2_3
Form2_4
...

Gut, aber nun will ich die Caption des Labels von Form2_3 ändern?
Wie stell ich das an...

Danke schonmal im Voraus!

Grüße,
Benny
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 04.12.10 11:38 
Hi,
Wenn du es direkt machst geht es so:
ausblenden Delphi-Quelltext
1:
TForm(FindComponent('Form2_3')).Caption:= 'mein neues caption';					


Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Sa 04.12.10 11:51 
Danke! Doch was ist mit dem Label, dessen Caption ich ändern will?
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Sa 04.12.10 12:02 
Eine recht elegante Möglichkeit wäre auch die Verwendung von TComponentList, setze mal bei Form2
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;


und schau mal (Button2) wie sich die Liste beim schliessen einer der TForm2 Instanzen verhält.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
unit Unit1;
// Thomas Wassermann explido-software.de
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Contnrs;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
  FList:TComponentList;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation
uses Unit2;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i:Integer;
begin
   i := FList.Add(TForm2.Create(Self));
   TForm(FList[i]).Show;
   TForm(FList[i]).Caption := 'Form ' + IntToStr(i);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Showmessage(IntToStr(FLIst.Count));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   FList:=TComponentList.Create;
   FList.OwnsObjects := true;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
   FList.Free;
end;

end.



EDIT:

zur 2. Frage

TForm2(wieauchimmergefundenesForm).Label1.Caption :=

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Sa 04.12.10 12:21 
VIELEN DANK! Es Funktioniert!!

Hab beide Varianten getestet und muss mal schauen welche sich besser für mein Programm eignet.