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



BeitragVerfasst: Mi 30.05.07 08:27 
Hallo allerseits!
Ich möchte eine simple tastensteuerung in Delphi programmieren. Dazu hab ich OnKeyDown und OnKeyUp verwendet. Leider funktioniert das ganze nicht, und da ich soetwas zum ersten mal schreibe, weis ich nicht warum.

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

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormKeyDown(Sender: TObject; var Key: Word);
    procedure FormKeyUp(Sender: TObject; var Key: Word);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word);
begin
 Label1.Caption:=VartoStr(Key);
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word);
begin
 Label1.Caption:='';
end;

end.


Weis jemad, was ich falsch gemacht habe?

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconGausi: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Mi 30.05.2007 um 14:48
Moderiert von user profile iconChristian S.: Topic aus Internet / Netzwerk verschoben am Mi 30.05.2007 um 17:10
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 30.05.07 09:17 
Moin und :welcome: im Forum!

Bitte verwende für Delphi-Quelltext die Delphi-Tags, nicht die "allg. Code"-Tags, dann haben wir auch das Syntaxhighlighting! ;)

user profile iconSADIC hat folgendes geschrieben:
Leider funktioniert das ganze nicht, und da ich soetwas zum ersten mal schreibe, weis ich nicht warum.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word);
begin
 Label1.Caption := VartoStr(Key);
end;

Weis jemad, was ich falsch gemacht habe?

Nimm mal IntToStr(), dann klappt das auch. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
SADIC Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 30.05.07 13:30 
user profile iconNarses hat folgendes geschrieben:
(...)
Nimm mal IntToStr(), dann klappt das auch. :idea: ;)

cu
Narses


Leider funktioniert es trotzdem nicht. Muss man vielleicht die Unit Windows (unter virtuelle Tastencodes in der Delphi-Hilfe angegeben) dem Projekt in irgendeiner bestimmten Form zufügen?
Soll heißen "Projekt\Dem Projekt hinzufügen..." habe ich shcon probiert, aber vielleicht muss man ja noch etwas anderes machen.
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Mi 30.05.07 13:39 
Die Unit Windows ist in deinem Projekt schon hinzugefügt.
Was ist denn das genaue Problem. Gibt es eine Fehlermeldung, wenn ja, welche ?
Wonko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 69



BeitragVerfasst: Mi 30.05.07 13:40 
Liegt Dein Problem daran, dass nach jedem KeyDown ein KeyUp kommt, und Du mit Deinem KeyUp das Ergebnis aus KeyDown überschreibst?

Entweder KeyUp weglassen oder key-Value in KeyUp statt KeyDown anzeigen lassen!
SADIC Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 30.05.07 13:47 
@azubi_20: Das Programm startet normal, keien Fehlermeldung. Es passiert ganz einfach gar nichts.

@wonko: Daran hatte ich auch schon gedahct und FOrmKeyUp herausgetrennt, das bringt aber leider auch nichts.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 30.05.07 13:48 
Ich rate jetzt mal und tippe darauf, dass KeyPreview der Form noch auf False steht. Wahrscheinlich kommen die Tastendrücke bei irgendeinem Ding auf der Form an und werden da nicht verarbeitet. Mit KeyPreview kommen die Dinger zuerst bei der Form an ;-)

_________________
We are, we were and will not be.
SADIC Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 30.05.07 13:58 
Leider auch keine Lösung des Problems. Bei google gibts auch keine Lösung, und die Delphi-Hilfe gibt es auch genauso vor...

Ich werd noch verrückt an der tastensteuerung. :P
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 30.05.07 14:03 
Dann halt Label1.Caption := Chr(Key);

_________________
We are, we were and will not be.
SADIC Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 30.05.07 14:08 
Auch nix.

Im Moment sieht das ganze so aus:
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormKeyDown(Sender: TObject; var Key: Word);
    procedure FormCreate(Sender: TObject);
//    procedure FormKeyUp(Sender: TObject; var Key: Word);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
KeyPreview:=True;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word);
begin
 Label1.Caption:=Chr(Key);
end;

//procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word);
//begin
// Label1.Caption:='';
//end;

end.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 30.05.07 14:12 
...und die Prozeduren, die du da hast, sind im Objektinspektor auch den passenden Events der Form zugeordnet? :gruebel:

_________________
We are, we were and will not be.
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Mi 30.05.07 14:12 
mach das im KeyPress-Ereignis :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
label1.Caption:=key;
end;
SADIC Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 30.05.07 14:31 
user profile iconGausi hat folgendes geschrieben:
...und die Prozeduren, die du da hast, sind im Objektinspektor auch den passenden Events der Form zugeordnet? :gruebel:

Das wars.^^ Ich hatte des einfach so in den Quelltext reingeschrieben.

Danke schön an alle Hilfswilligen!!!