Autor Beitrag
maniac_89
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Di 07.06.05 10:02 
Hallo,
ich wollte fragen wie es möglich ist das beim Start einer Delphi Anwendung auch gleich noch ein zweites Fenster anzuzeigen. Ich habe das schon versucht über FormCreate und dan einfach reingeschrieben Form2.show. Dann kommt aber immer eine Fehlermeldung. Ich hoffe ihr könnt mir helfen.

Von Steffen, Maniac_89
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 07.06.05 10:20 
Hmm, zum Beispiel, indem du das direkt in den Projekt-Quelltext schreibst.
Delphi-Menü -> Projekt -> Quelltext anzeigen

Da werden die Formulare erzeugt und danach kannst du die auch mit Show anzeigen.

So funktioniert übrigens auch ein einfacher, wenn auch nicht idealer, SplashScreen.

Abgesehen davon: In WELCHES FormCreate hast du das Show getan? Nach deiner Beschreibung vermute ich, dass du Form2.Show in Form2.FormCreate aufgerufen hast und das geht nicht.
Was wohl am sinnvollsten ist, wenn meine Vermutung zutrifft:
Tu das Form2.Show in Form1.onShow, am besten so:
ausblenden Delphi-Quelltext
1:
2:
3:
if Form2 = nil then
  Form2 := TForm2.Create(Self);
Form2.Show;

Wenn du es so machst kannst du auch Form2 in den Projektoptionen aus den automatisch erzeugten Formularen rausnehmen, musst das aber nicht...
maniac_89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Di 07.06.05 10:35 
Hier habe ich den Quelltext:

ausblenden Form1
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
form2.Show;  // Hier ist das Problem
end;

end.



ausblenden Form2
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:
unit Unit2;

interface

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

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

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin

end;

end.


Ich hoffe ihr könnt mir helfen

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 07.06.05 10:40 
Nimm einfach den Quelltext, den ich angegeben habe! Der Fehler liegt daran, dass Form2 erst nach Form1 erzeugt wird, und damit noch nicht verfügbar ist, wenn Form1 erzeugt wird.
Die ersten beiden Zeilen meines Codes erzeugen Form2 falls nötig und dann läuft das auch.
Falls du an die Stelle, wo der Feeler :wink: auftritt, mal nen Haltepunkt setzt, wirst du mit deinem Code feststellen, dass Form2 = nil, also nix ist. Und mit nix kannst du auch nix machen.
maniac_89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Di 07.06.05 10:40 
OK, Danek hats sich erledigt