Autor Beitrag
GR-Thunderstorm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Mi 10.05.06 10:58 
Hi Leutz,
ich will ein OnKeyUp Event erzeugen, aber der will nicht starten...

Der Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key ='d' then
image1.Picture.LoadFromFile('C:\...\bild.bmp');
end;


Der Fehler besagt "Incompatible Types" und der Cursor springt hinter das then...

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 10.05.06 11:00 
Key ist vom Typ Word und du vergleichst das mit einem Typ Char/String.
Das passt nicht zusammen, wie auch die Fehlermeldung mitteilt.
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Mi 10.05.06 11:08 
Hmm stimmt, hab ich übersehen. Aber manuell auf Char ändern kann ich es leider nicht..

Bei der funktion "FormKeyPress" macht er doch aber auch ne Char-Variable...?? :?


Es gab doch mal nen Befehl, der einen Buchstaben in den jeweiligen ASCII Code umwandelt, also eine Zahl quasi... Wisst ihr wie der geht?
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mi 10.05.06 11:11 
ausblenden Delphi-Quelltext
1:
Ord('a')					

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Mi 10.05.06 11:19 
versuche es mal mit folgendem :

if Key=ord('D') then image1.icture.loadfromfile('bild1.bmp');
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 10.05.06 11:26 
Und dran denken, dass ord('d') <> ord('D') ist.
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Mi 17.05.06 09:51 
Das mit dem ord('d') führt er jetzt soweit aus, aber wenn ich jetzt die Taste "d" loslasse, erkennt er dies dennoch nicht und das onkeyup event wird nicht gestartet.
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Mi 17.05.06 10:16 
Das ist wirklich ein Ding - gibt auch bei mir keine Reaktion (hab auch in der Form KeyPreview auf true gesetzt...) :roll:
Mit Keypress geht's:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key in ['d','D'] then Label1.Caption:='Ob das geht?';
end;

Aber löst wahrscheinlich nicht dein Problem.
ABER, kann mir mal jemand verraten, warum "Key" bei KeyUp und KeyDown vom Typ Word ist, bei KeyPress aber vom Typ Char?

Edit:
Hab nix in meinen schlauen Büchern oder OH gefunden, das die Vorgänge bei KeyUp und KeyDown für einen noob erklärt. Jedenfalls funktioniert die IF Abfrage mit "Ord('d') nicht. Das hier reagiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
label1.caption :='';
if Key = 68 then label1.caption:=IntTostr(Key);  //68 dezimal für 'D'
end;

Das verrückte ist, daß hier 'd' oder 'D' keinen sofortigen Unterschied zeigen. Aber offensichtlich spielen alle Tasten bei KeyUp/Down eine Rolle.
Fühle mich nicht sehr wohl, weil ich mangels Info keine Ahnung habe, was da eigentlich passiert. :shock: :?:
Ydobon
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 42



BeitragVerfasst: Mi 17.05.06 17:14 
Die Funktion gibt als Tastencode einfach den Ordinalwert des Großbuchstabens zurück, die kommen schließlich auch früher. Ob nun Klein- oder Großbuchstabe gemeint war, bekommt man mit dem Wert für TShiftState heraus.