Autor Beitrag
MichiM
Hält's aus hier
Beiträge: 8



BeitragVerfasst: So 18.12.05 13:12 
Hi,

bin ziemlicher Delphi-Anfänger und arbeite grad mit Delphi 2.0 in einer Developer Version, mit der man zwar scheinbar keine .EXE erstellen kann, die aber zum Üben schon mal geht. ;)

Hätte da mal ein paar Fragen zum Reinkommen:

Hab in einem Tutorial (http://www.dsdt.info/tutorials/erstesprog/?page=8)
z.B. schon mal einen Tip gefunden, wie man ein zweites Form öffnet, was mich interessiert hat:

Form2.ShowModal;

Hab das zweite Form natürlich angelegt, aber es erscheint nicht, wenn ich den Button klicke.

Hier die Projekt-Quellcodes (Dateinamen sind etwas unglücklich, aber soll ja nur ein Test sein ;) ):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
program Project1;

uses
  Forms,
  Projekt2 in '\Program Files\Borland\Delphi 2.0\Bin\Projekt2.pas' {Form1},
  Unit2 in '\Program Files\Borland\Delphi 2.0\Bin\Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.


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:
unit Projekt2;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Grafik;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject);
begin
   Form2.ShowModal;
   Grafik;
end;

procedure TForm1.Grafik;

   var EingabeWert1 : Real;
       EingabeWert2 : Real;
       Wert1        : Integer;
       Wert2        : Integer;

   begin

     EingabeWert1 := StrToFloat (Edit1.Text);
     EingabeWert2 := StrToFloat (Edit2.Text);


     if ( EingabeWert1 > EingabeWert2 ) then
       begin
         Wert1 := 400;
         Wert2 := Round (EingabeWert2 / EingabeWert1 * 400)
       end
     else
       begin
         Wert2 := 400;
         Wert1 := Round (EingabeWert2 / EingabeWert1 * 400)
       end;

     Panel1.Caption := Edit1.Text;
     Panel2.Caption := Edit2.Text;

     Panel1.Width := Wert1;
     Panel2.Width := Wert2;

  end;

end.



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

interface

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

type
  TForm2 = class(TForm)
    Label1: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

end.


Was fehlt noch?

MfG
Michi

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconGausi: Topic aus Sonstiges verschoben am Do 22.12.2005 um 09:01
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.12.05 13:36 
user profile iconMichiM hat folgendes geschrieben:
Hi,
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
program Project1;

uses
  Forms,
  Projekt2 in '\Program Files\Borland\Delphi 2.0\Bin\Projekt2.pas' {Form1},
  Unit2 in '\Program Files\Borland\Delphi 2.0\Bin\Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt


Du musst die zweite Form erst erstellen, bevor du sie öffnen kannst. Normalerweise müsste doch ein Fehler gekommen sein (EAccessViolation), oder?

Grußa alais5000

_________________
Programmers never die, they just GOSUB without RETURN
MichiM Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: So 18.12.05 13:45 
Titel: kein Erfolg
Hi alias5000,

Application.CreateForm(TForm2, Form2);

an der genannten Stelle einzufügen
hab ich auch schon probiert, bewirkt aber nichts.
Ich krieg aber auch keinen Compilerfehler, wenn ich es rauslasse.

Vielleicht ist Version 2.0 doch nicht das Richtige...? :)


Gruß Michi
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.12.05 13:50 
OK, muss mich erstmal korregieren, das da oben heißt natürlich Form2 statt Form1 und TForm2 statt TForm1. Aber du hast das ja verstanden :wink:
Naja kann das sein, dass die Position der zweiten Form außerhalb des Bildchirmes liegt oder so?

_________________
Programmers never die, they just GOSUB without RETURN
MichiM Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: So 18.12.05 17:57 
Hm, geht dennoch nicht. :)

Probier ich:
ausblenden Quelltext
1:
2:
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);

, wird Form1 erzeugt, nicht jedoch Form2.

Probier ich:
ausblenden Quelltext
1:
2:
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm1, Form1);

, dann umgekehrt.

Das jeweils andere geht auch dann nicht auf, wenn ich das erscheinende wegklicke.
Bin ich da evtl. im SDI-Modus? Oder muss ich Form2 evtl. irgendwie auf Form1 aufsetzen?
maxstegi
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 26

WIN XP SP2 (Suse Linux 10.0 OSS)
Delphi 2005 PE
BeitragVerfasst: So 18.12.05 18:01 
Titel: visible
Kann es sein, dass in der zweiten Form die Eigenschaft

visible := true

fehlt???



Max
MichiM Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: So 18.12.05 18:04 
Rrrr, war wieder zu einfach, danke. ;)