procedure TForm1.Form1KeyDown(....);begin // if you have to do things only for this form, do it before this line. MyKeyDownMethode(Screen.ActiveControl, Key, Shift);end;
procedure MyKeyDownMethode(Sender: TObject; var Key: Word; Shift: TShiftState);begin // ALLWAYS DO SAFE CASTING!!! if Sender is TEdit then with Sender as TEdit do begin // place your code here end;end;
function KeyIsNumeric(Key: Word; Shift: TShiftState): Boolean;begin Result := (Key in [VK_NUMPAD0..VK_NUMPAD9]) or ((Shift = []) and (Key in [VK_0..VK_9]));end;procedure GoToNextControl(AWinCtrl: TWinControl; GoForward, ChkTabStop: Boolean);begin UnCtrl.SelectNext(AWinCtrl, GoForward, ChkTabStop);end;
{ Since I don't know what you check I did this... }TForm1.Form1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin if (key = 13) and (Shift = []) then begin Key := 0; if sender is TWinControl then begin GoToNextControl(TWinControl(Sender), True True); end; Exit; end; if not KeyIsNumeric(Key, Shift) then begin Key := 0; // Erases the pressed key end;end;