Autor Beitrag
dontello
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60
Erhaltene Danke: 2



BeitragVerfasst: Di 15.03.11 23:36 
Hallo,

ich habe zwei Formulare. Ich möchte nun das erste Formular schließen und das zweit aufrufen. Außerdem soll eine Variable übergeben werden. Wie kann ich dies realisieren?

Mit "Form1.Close;" schließe ich die erste Form. Bei "Form2.Show;" bekomme ich allerdings eine Zugriffsverletzung.

Wo liegt mein Fehler?
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 15.03.11 23:54 
user profile icondontello hat folgendes geschrieben Zum zitierten Posting springen:
Mit "Form1.Close;" schließe ich die erste Form. Bei "Form2.Show;" bekomme ich allerdings eine Zugriffsverletzung.

Ist Form1 dein Hauptformular? Hast du die Instanz von Form2 (Form2 := TForm.Create()) erzeugt?
Wie schaut dein sonstiger Source-Code aus?
dontello Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60
Erhaltene Danke: 2



BeitragVerfasst: Di 15.03.11 23:59 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TLogIn.btn_loginClick(Sender: TObject);
begin
  login.Close;
  haupt.Main.Show;
end;


login = form1
haupt = form2

unter uses habe ich die Form "haupt" mit eingefügt

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Mi 16.03.11 00:14 
Da geht aber nichts hervor das Form1 oder Form2 deine MainForm ist?
Im allgemeinen ist ja Form1 die Mainform(dein Prog). Wenn Du Close in der MainForm aufrufst und gleichzeitig ne neu Form2 zum anzeigen bringen willst wird dies nicht gehen!

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 16.03.11 00:14 
Kann den Fehler so nicht reproduzieren oder nachvollziehen. :nixweiss:
Hast du mal debugged? :idea:

user profile iconALF hat folgendes geschrieben Zum zitierten Posting springen:
Da geht aber nichts hervor das Form1 oder Form2 deine MainForm ist?

Naja, er schrieb ja, dass Form2 seine "hauptform" ist.
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Mi 16.03.11 00:28 
Er hat sie "haupt" genannt, das muss aber nicht zwingend heißen das es auch die Hauptform ist.
Ich vermute, dass "login" die Hauptform bei ihm ist und es daher nicht funktioniert. ;)

_________________
Es gibt 10 Gruppen von Menschen: diejenigen, die das Binärsystem verstehen, und die anderen.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 16.03.11 05:21 
user profile icondontello hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TLogIn.btn_loginClick(Sender: TObject);
begin
  login.Close;
  haupt.Main.Show;
end;
Was ist denn Main? :gruebel:

Dein Konzept ist aber auch nicht so günstig. Erzeuge das Login-Formular besser im Projektquelltext (Projekt --> Quelltext anzeigen). Dann kannst du dort auch direkt verhindern, dass das Hauptfenster überhaupt erzeugt wird, wenn der Login nicht klappt.