Einzelnen Beitrag anzeigen

Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#13

Re: Navigation mit Pfeiltasten

  Alt 20. Sep 2006, 15:22
generisch, das wort heißt generisch!

Delphi-Quellcode:
var ControlIndex: Integer; //global, am besten mit 0 initialisieren

procedure TForm1.KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var Controls: array of TControl;
begin
if not ((Key = VK_LEFT) or (Key = VK_RIGHT)) then
  Exit; //wir wollen ja nicht alles abwürgen

//die zuweisung sollte man natürlich auch global machen
Setlength(Controls,4);
Controls[0] := Btn1;
Controls[1] := Btn2;
Controls[2] := Btn3;
Controls[3] := Btn4;

case Key of
  VK_RIGHT: Inc(ControlIndex);
  VK_LEFT: Dec(ControlIndex);
end;

if ControlIndex < low(Controls) then
  ControlIndex := high(Controls)
else if ControlIndex > high(Controls) then
  ControlIndex := low(Controls);

ActiveControl := Controls[ControlIndex];
end;


[edit=SirThornberry]Quelltext auf Wunsch korrigiert - Mfg, SirThornberry[/edit]
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat