Autor Beitrag
Eagle.23
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Sa 28.08.04 17:28 
Hi, folgendes Problem: Ich möchte von Form1 aus in die 2.te Form wechseln kriege aber folgende Fehlermeldung: "Komponente mit Button1 existiert bereits" Danke für die Hilfe im voraus. (99% des Quelcodes sind zwar für das eigentlich Problem völlig uniteressant aber ich poste ma trotzdem alles :wink: )
Quellcode Form1:
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:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
var
  Form1: TForm1;
  wurzel : Array[1..6of Zeiger;


const Distances : TDistances = ((0,0,28,0,0,24),
                                (0,0,15,20,0,0),
                                (28,15,0,12,0,0),
                                (0,20,12,0,13,0),
                                (0,0,0,13,0,11),
                                (24,0,0,0,11,0));


implementation

uses Ways;



Procedure TForm1.Print_Distances_Matrix;
Var a,b : Integer;
Begin
     For a:=1 to 6 do
          For b:=1 to 6 do
              Tedit(Form1.findcomponent('Cell'+IntToStr(a)+IntToStr(b))).text:=IntToStr(Distances[a,b]);
End;


Procedure TForm1.List_Print;
Var a : Integer;
    Hilf : Zeiger;
Begin
     For a:=1 to 6 DO
     Begin
          hilf:=wurzel[a];
          While Hilf <> NIL do
          begin
               Tedit(FindComponent('ListEdit'+IntToStr(a))).Text :=Tedit(FindComponent('ListEdit'+IntToStr(a))).Text + ' -> ' + IntToStr(hilf^.Distance) + '(' + Hilf^.City_Name + ')';
               Hilf := Hilf^.Next;
          end;
     End;
End;


Procedure TForm1.MatrixListe1Click(Sender: TObject);
Var a,b : Integer;
    Hilf, lauf: Zeiger;
Begin
     For a:=1 to 6 do
     Begin
          Wurzel[a] := NIL;
         For b:=1 to 6 do
             If Distances[a,b] <> 0 then
             begin
                  New(Hilf);
                  Hilf^.Distance := Distances[a,b];
                  Case b of 1 : Hilf^.City_Name:= 'Laie';
                            2 : Hilf^.City_Name:= 'Maiti';
                            3 : Hilf^.City_Name:= 'Wahiawa';
                            4 : Hilf^.City_Name:= 'Perl-City';
                            5 : Hilf^.City_Name:= 'Honolulu';
                            6 : Hilf^.City_Name:= 'Kanehohe';
                  end;
                  If Wurzel[a] = NIL then
                  begin
                       Wurzel[a] := Hilf;
                       lauf:=Hilf;
                       Hilf^.Next := NIL;
                  end else
                  begin
                       Lauf^.Next := Hilf;
                       Lauf := Lauf^.next;
                       Hilf^.Next := NIL;
                  end;
             end;
         End;

         List_Print;
End;


procedure TForm1.FormActivate(Sender: TObject);
begin
 Form1.Print_Distances_Matrix;
 Form1.List_Print;
end;


procedure TForm1.Beenden1Click(Sender: TObject);
begin
halt;
end;



{$R *.DFM}



procedure TForm1.Wegberechnung1Click(Sender: TObject);
Var NewForm : TForm2;
begin
     NewForm.Create(self);
     NewForm.ShowModal;
     NewForm.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
Var NewForm : TForm2;
begin
     NewForm.Create(self);
     NewForm.ShowModal;
     NewForm.Free;

end;

end.


Quellcode Form2:
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:
unit Ways;

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.Button1Click(Sender: TObject);
begin
     halt;
end;

end.

Moderiert von user profile iconUGrohne: Code- durch Delphi-Tags ersetzt.
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Sa 28.08.04 19:17 
Vergleiche:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
Var NewForm : TForm2;
begin
     NewForm := TForm2.Create(self);
     NewForm.ShowModal;
     NewForm.Free;
end;

_________________
Gruß
Martin
Eagle.23 Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: So 29.08.04 11:29 
Hab den Fehler jetzt berichtigt, krieg jetz aber das Form1 und Form 2 inkompatible Typen sind.

MfG
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 30.08.04 10:56 
Hallo!

Na dann hast du wohl irgendwelche Variablen falsch deklariert. Zeit doch mal den Code-Abschnitt der zu diesem Fehler führt.

Gruß
Tino
Eagle.23 Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mo 30.08.04 20:26 
Er bringt bei der Zeile mit NewForm:=Create(self) den Fehler...
Böser Borstel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154



BeitragVerfasst: Di 31.08.04 08:25 
eine Form erstellt man so: Application.CreateForm(TForm1, Form1);
denke aber daran deine Fenster-Objekte auch irgendwann wieder freizugeben