Autor Beitrag
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 18.12.06 23:21 
Hallo!

Ich habe ein Problem (was sonst). Und zwar habe ich ein Eingabefeld um mehrere Zahlen hintereinander einzugeben. Das ganze läuft wie an der Supermarktkasse: Zahl rein->Return->Fenster geht zu->Interaktion->nächste Zahl.

Um dem Nutzer das etwas einfacher zu machen, habe ich das VK_RETURN schon als Modalresult umgesetzt. Nun ist es aber wenn man sich vertippt hat doof, vom Ziffernblock weg zu gehen, und die Rücktaste zu nehmen. Da dachte ich mir ok, nehme ich das Ziffernblock-Minus und setze das um. Geht aber nicht.

Mein Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm2.edNumKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
    VK_RETURN : ModalResult:= mrOK;
    VK_SUBTRACT : Key:= VK_BACK;
  end;
end;

procedure TForm2.edNumKeyPress(Sender: TObject; var Key: Char);
begin
  case Key of
    '0'..'9' : ;
  else
    Key:= #0;
  end;
end;


Wenn ich das Minus drücke, stimmt das Case, Key wird 8, aber im Edit wird nichts gelöscht.
Im KeyPress hab ichs auch versucht, aber da kann man VK_SUBTRACT nicht von '-' unterscheiden.

Wie kann ich also mein Ziel erreichen?

Grüße,
Sebastian

PS: editiert, geht aber immer noch nicht.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 19.12.06 08:01 
Hallo,

durch verändern von Key kann man keine Taste senden.

Entweder man nutzt dazu Keybd_Event oder die Variante ist auch eine Alternative:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm2.edNumKeyDown(Sender: TObject; var Key: Word;  
  Shift: TShiftState);  
begin  
  case Key of  
    VK_RETURN   : ModalResult:= mrOK;  
    VK_SUBTRACT : begin
                  If edNum.SelLength = 0 then
                    //Zeichen vor dem Cursor markieren    
                    edNum.SelLength := -1;
                  edNum.ClearSelection;  
                  end;  
  end;  
end;


Außerdem finde ich das eleganter:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm2.edNumKeyPress(Sender: TObject; var Key: Char);  
begin  
  if not (Key in ['0'..'9']) then
    Key:= #0;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Di 19.12.06 12:53 
Ahh, sehr schön.

Das man den Key zwar löschen, aber nicht ändern kann, wusste ich nicht.

Und beim 2. Code: stimmt, da standen vorher noch andere Sachen drin, da war das Case noch übrig.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."