Autor Beitrag
raven_22
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: Fr 13.08.04 19:47 
Hallo !

Ich erzeuge mit untenstehendem Code ein Dialogfeld mit Label, Edit und Button.
Es ist mir leider nicht möglich auf einen Buttonklick zu reagieren.
Wenn ich also auf den erzeugen Button der erzeugten Form klicke, solle etwas passieren.
Kann mir da einer Helfen ?
Das erzeugen und Anzeigen geht ja, aber der Rest nicht.

LG raven 8)

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

interface

uses
  ...

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }

  end;

var
  Form1: TForm1;
  Dialog:tForm;
  Edit:TEdit;
  Info:TLabel;
  Button:TButton;

implementation

{$R *.dfm}

Function PW_Dialog:String;
begin
Dialog:=TForm.Create(Dialog);
Info:=TLabel.Create(Info);
Edit:=TEdit.Create(Edit);
Button:=TButton.Create(Button);
Info.Parent:=Dialog;
Edit.Parent:=Dialog;
Button.Parent:=Dialog;
Dialog.Caption:='Screensaver PW';
Info.Caption:='Bitte Passwort eingeben !';
Dialog.Width:=Info.Width+30;
Info.Top:=10;
Info.Left:=10;
Edit.Top:=Dialog.top+30;
Edit.left:=Dialog.left+10;
Edit.PasswordChar:='*';
Button.Top:=Edit.top+30;
Button.Left:=Edit.left+25;
Button.Caption:='OK';
Dialog.Height:=Button.top+70;
Dialog.BorderStyle:=bsDialog;
Dialog.Position:=poScreenCenter;
Dialog.Show;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
PW_Dialog;
end;

end.



Moderiert von user profile iconKlabautermann: Topic aus Sonstiges verschoben am So 15.08.2004 um 05:05

_________________
---_-= raven_22 =-_---
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 13.08.04 20:09 
Im folgenden wird durch einen bereits existierenden Button ein zweiter erzeugt. Daraufhin wird dem neuen Button ein OnClick-Ereignis zugewiesen. Schaus dir mal an...
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:
unit Unit1;

interface

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

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

var
  Form1: TForm1;
  Button2: TButton;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Button2 := TButton.Create(Form1);
With Button2 do
begin
  left:=20;
  top:=100;
  parent:=form1;
  OnClick := Klick;
end;
end;

procedure TForm1.Klick(Sender: TObject);
begin
  (Sender as TButton).Caption := 'Ich reagiere!';
end;
end.


Moderiert von user profile iconPeter Lustig: Delphi-Tags repariert
raven_22 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: Fr 13.08.04 22:10 
Danke !

Ich solle mir auch mal dieses ‚With XYZ do’ angewöhnen, spart viel Schreibarbeit.
Aber den Code muss normalerweise ja nur ich lesen und verstehen.
Dieses Beispiel war genau das richtige für mich, ich hab’s nun verstanden.
Ein Problem ist da aber noch immer, das OnKeyDown-Ereignis !
Wie reagiert Edit auf dieses Ereignis ?
Die Eingabe soll per Enter übernommen werden.

LG raven 8)
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:
unit Unit1;

interface

uses
  ...

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

var
  Form1: TForm1;
  Edit : TEdit;
  Info : TLabel;
  Button :TButton;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Edit := TEdit.Create(Form1);
With Edit do
begin
  left:=20;
  top:=30;
  caption:='';
  PasswordChar:='*';
  parent:=form1;
  OnKeyDown := OnKeyDown;
end;

Info := TLabel.Create(Form1);
With Info do
begin
  left:=20;
  top:=10;
  caption:='Bitte Passwort eingeben !';
  parent:=Form1;
end;

Button := TButton.Create(Form1);
With Button do
 begin
  left:=40;
  top:=60;
  caption:='OK';
  parent:=form1;
  OnClick := Klick;
 end;

end;

procedure TForm1.Klick(Sender: TObject);
begin
  if edit.Text = 'Pass' then
   begin
   showmessage('Richtig');
   Info.Free;
   edit.Free;
   button.Free;
   end

  else
  showmessage('Falsch');
end;

procedure TForm1.OnKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=char(13) then
 begin
  if edit.Text = 'Pass' then
   begin
   showmessage('Richtig');
   Info.Free;
   edit.Free;
   button.Free;
   end

  else
  showmessage('Falsch');
 end;
end;

end.

_________________
---_-= raven_22 =-_---
Stoffel1984
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Fr 13.08.04 23:08 
raven_22 hat folgendes geschrieben:
Aber den Code muss normalerweise ja nur ich lesen und verstehen.


Man sollte Code schon übersichtlich schreiben!
In nem halben Jahr regst dich drüber auf ;)
Auch Kommentieren und ne sinnvolle EInrückung (die ich nicht erkennen konnte :wink: ) wirkt oft Wunder

Grüße, Stoffel
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Sa 14.08.04 06:43 
Hallo!

raven_22 hat folgendes geschrieben:
Die Eingabe soll per Enter übernommen werden.

Dann stelle die Eigenschaft "Default" des Buttons auf True und das Standardverhalten von Windows wird auch in deiner Anwendung unterstützt.

Gruß
Tino
raven_22 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: Sa 14.08.04 10:15 
Ich meinte das OnKeyDown-Ereignis von EDIT !
Also der Benutzer gibt in der erzeugen EDIT etwas ein und bestätigt dies mit Enter.
Bei einer normalen Edit geht dies wie folgt.
Nur wie kann ich das bei der Erzeugten EDIT machen ?

LG raven 8)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key = 13 then
showmessage(edit1.Text)
else
key:=0;
end;

_________________
---_-= raven_22 =-_---
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Sa 14.08.04 13:15 
Vielleicht zuerst mal in der Hilfe nachschaun wenn schon irgendein Tipp oder so kommt... ;)

Wenn die Default-Eigenschaft des Buttons auf True ist wird automatisch das OnClick-Ereignis des Buttons ausgelöst wenn die Enter-Taste gedrückt wird. Ansonsten kannst du auch auf dieselbe Art und Weise wie beim Button das Ereignis zur Laufzeit zuweisen...

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 14.08.04 14:40 
Hmm, du fragst wie man das nun mitnem Edit macht?
Na das ganze in hellgelb:

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

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  myEdit: TEdit;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  myEdit:=TEdit.Create(Form1);
  with myEdit do
  begin
    left:=20;
    top:=40;
    parent:=form1;
    OnKeyDown:=KeyDown;
  end;
end;


procedure TForm1.KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
begin
  (Sender as TEdit).Text:='KeyDown ausgelöst!';
end;

end.
raven_22 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: So 15.08.04 02:18 
@Elite*

Danke !

Wenigstens einer hat verstanden was ich wollte.
Ich dachte schon ich würde eine fremde Sprache sprechen oder so.
Du gehörst wirklich zur Elite, dass merkt man.


@All
Ist schon mal jemand aufgefallen, dass ich im letzten Eintrag nichts von Button oder Buttonklick-Ereignissen geschrieben habe ?
Es ging mir echt nur um folgendes !

LG raven 8)

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

interface

uses
  ...

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure OnButtonClick(Sender: TObject);
    procedure EditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditChange(Sender: TObject);
    procedure EditKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Edit : TEdit;
  Info : TLabel;
  Button :TButton;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Edit := TEdit.Create(Form1);
With Edit do
begin
  left:=20;
  top:=40;
  caption:='';
  parent:=form1;
  OnKeyDown:=EditKeyDown;
  OnChange:=EditChange;
  OnKeyUp:=EditKeyUp;
end;

Info := TLabel.Create(Form1);
With Info do
begin
  left:=20;
  top:=10;
  caption:='Bitte Text eingeben und'+#13+'mit ENTER bestätigen !';
  parent:=form1;
end;

Button := TButton.Create(Form1);
With Button do
 begin
  left:=40;
  top:=80;
  caption:='OK';
  parent:=form1;
  OnClick := OnButtonClick;
 end;

end;

procedure TForm1.OnButtonClick(Sender: TObject);
begin
  showmessage('Button geklickt !');
end;

procedure TForm1.EditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);  
begin
  if Key=13 then
   begin
    Info.Caption:=Edit.Text;
    Edit.Clear;
   end
  else
   begin
    Key :=0;
   end;
end;

procedure TForm1.EditChange(Sender: TObject);
begin
  Form1.Caption:='Text wird eingegeben !';
end;

procedure TForm1.EditKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  Form1.Caption:='';
end;

end.

_________________
---_-= raven_22 =-_---