How to implement "Enter" in the application into TAB?
That is to say, when pressing the Enter key, the resulting effect is to press the TAB button.
Here is the method I often use:
Add the following code in your data module:
Interface
. . . . . .
Type
TMESSAGEHANDLER = Class // Make Enter messages to TAB messages
Class Procedure AppMessage (var Msg: TMSG; VAR HANDED: BOOLEAN);
END;
IMPLEMENTATION
Class Procedure TMESSAGEHANDLER.AppMessage (VAR Msg: TMSG; VAR HANDED: BOOLEAN);
Begin
if msg.Message = WM_Keydown Then
IF (msg.wparam = vk_return) and
(
Screen.Activeform.ActiveControl is Tedit OR
(Screen.Activeform.ActiveControl Is Tcombobox) or
(Screen.Activeform.ActiveControl is tcheckbox) or
(Screen.Activeform.ActiveControl is tradiobutton)
/ / Can add a needed control
)
THEN
Begin
Msg.wparam: = vk_tab;
end
ELSE IF (msg.wparam = vk_return) and
(
Screen.ActiveForm.ActiveControl Is TDBGRID)
)
THEN
Begin
With screen.activeform.activeControl Do
Begin
IF SELECTEDINDEX <(Fieldcount-1) THEN
SELECTEDINDEX: = SELECTEDINDEX 1 {Move to the next field}
Else
SELECTEDINDEX: = 0;
END;
END;
END;
In order to make the entire application to implement the main function, add the following code in the onCreate event of the main form:
Procedure tfmmain.formcreate (sender: TOBJECT);
Begin
Application.onMessage: = tMessageHandler.AppMessage;
END;
So far, your application has implemented this ENTER-> Tab conversion.