A program can work "perfect" even if it's bug prone or safe. This is a fact and believe me: I can tell you about it.
BUT if a program is is bug-prone, mantainance becomes ... a BIG PROBLEM.
Now your program seems small and those things are not an issue, but if it starts to get bigger it will. And soon you will see how a beautifull small program becomes a snowball an ends like an avalanch. This is why people say: that code is buggy. And they're right.
If you can do things right, do it right from start. The best way to solve a problem is before it happens or while it's easy. And Object Oriented Programming it's the best way to avoid those problems.
For instance:
You have a Form with it's Components, and a Unit with functions, And god knows where is the Data and it's methods (This shoul be a class in a sepparated Unit).
Your solution as we understood is: a Unit (wich doesn't know much of a Component's context) to handle Form's component's input. It's something like: a cab driver let passengers to drive the cab without switching positions!
A different (and better way) to do the same thing is:
Your Unit contains general purpouse procedures and functions like:
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;
The Form:
{ 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;
Note: if you need keyboard's shortcuts you can do it with TActionList Component in the standard component's tab.
If you find yourself doing the same change in many different methods and/or different units, forms, classes. Then you will know that you're in the middle of a snowball rolling down the mountain in an avalanch... and it gonna' hurt!