Autor Beitrag
Silence
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58

Win XP Prof
Delphi 7
BeitragVerfasst: Di 06.03.07 15:13 
Hey

bin grade dabei ein programm zu schreiben, dass aus 3 Formularen besteht. Ich will eine Variable aus Form1 in Form3 benutzen. aber es tut nicht. so ist die variable deklariert:

ausblenden Delphi-Quelltext
1:
2:
3:
var
  Form1: TForm1;
  projekt: string = 'Homepage';


so wird sie verändert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
statusbar1.SimpleText := listbox1.Items.Strings[listbox1.itemindex];
form3.Caption := listbox1.Items.Strings[listbox1.itemindex];
projekt := listbox1.Items.Strings[listbox1.itemindex];
form3.show;
end;


und so wird sie dann im Form3 benutzt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm3.FormCreate(Sender: TObject);
var mm : IXMLNode;
begin
 XMLDocument1.LoadFromFile(extractFilepath(Application.exename) + projekt + '\Info.xml');
 mm := xmldocument1.DocumentElement;
 edit1.Text := mm.ChildNodes['projekt'].ChildNodes['name'].Text;
 edit2.text := mm.ChildNodes['projekt'].childnodes['kurzform'].Text;
 edit3.text := mm.ChildNodes['projekt'].childnodes['version'].Text;
 XMLDocument1.SaveToFile(extractFilepath(Application.exename) + projekt + '\Info.xml');
end;


ich bekomm aber bei der procedure TForm3.FormCreate immer den fehler, dass der pfad nicht gefunden werden kann. wenn ichs per showmessage ausgeb is es auch einfach leer.

was is da falsch?
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Di 06.03.07 15:16 
Anscheinend wird der String erst nach dem OnCreate initialisiert. :? Du kannst ja mal versuchen, den String in Form1.OnCreate oder Form3.OnCreate zu initialisieren, anstatt schon beim deklarieren.
Silence Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58

Win XP Prof
Delphi 7
BeitragVerfasst: Di 06.03.07 15:26 
wenn ich es so mach

ausblenden Delphi-Quelltext
1:
2:
3:
var
  Form1: TForm1;
  projekt: string;


Dann bekomm ich gleich ein fehler das er im form3 das objekt nicht finden kann.
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Di 06.03.07 15:33 
Wann wird denn die Form 3 created? Im DPR?!? Da hast Du doch noch garnicht auf die Listbox in Form1 doppelt geklickt, also ist Deine Variable noch leer.

Probier mal statt im OnCreate in OnShow von Form3 auf die Variable zuzugreifen.

...oder die Form3 manuell zu erstellen, nachdem Du in die Listbox geklickt hast.
Silence Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58

Win XP Prof
Delphi 7
BeitragVerfasst: Di 06.03.07 15:37 
also mit onshow tuts. vielen dank.