Archive

Posts Tagged ‘ani’

How to Focus the Next Edit Control With the Enter Key II

December 15th, 1999 m3Rlin 1 comment

When creating forms with a lot of data entry you may want to consider the option to let the user focus the next edit control by hitting the Enter key. The default key is Tab which can become annoying :-)
All we have to do is add the following code the each TEdit control on the form. You can do so by holding down the shift key and selecting each control. Then click the ObjectInspector and double click on OnKeyPress to create a shared event for all the controls. Then enter this code in the event procedure:

  ...
  uses
    Windows;
  ...
  if Key = #13 then begin
    { Make Windows focus the next edit control }
    Perform(WM_NEXTDLGCLTL, 0, 0);
    { Eat the enter key }
    Key := #0;
  end;
  ...

This code will work only with the controls that use this OnKeyPress event.
If you want all the edit controls on the form to act this way use a different way. This code does not require each edit control to use the above routine. Just the form’s KeyPreview property to True. Now add this code to the form’s KeyUp event and your all set :-) If, for some reason you want to exclude any edit control from using Enter key instead to pass the focus all you have to do is modify the if condition to exclude certain edits. Instead of using there names you may want to consider the Tag property for this.

  ...
  if (Key = VK_RETURN) and ([ssCtrl, ssShift] * Shift = []) then
    Perform(WM_NEXTDLGCTL, 0, 0);
  ...

Note: Tip #42 refers to this topic too.

Delphi Component Messages

December 15th, 1999 m3Rlin 1 comment

Delphi sends messages for notification of events that are only applicable to Delphi components. They are like Windows messages in use. If you have a component that publishes the Font property the component probably needs to be repainted if any subproperties in the Font are changed. Changing the Font property does not necessarily generate a Windows event but the control still needs to know about the change. Component messages serve this purpose.

This is a complete listing of the component messages and what they do. They are all defined in the controls.pas unit. This is a list of Delphi 5 component messages. The messages marked Notification Only do not pass any useful information to the message handler and do not expect the message handler to return a value. The messages on which I could not find information about I marked with a question mark “?”.

If you have any information about component messages and they are not listed here let me know, so as I can update this table. m3rlin@delphifaq.net

CM_ACTIONEXECUTE ?
Unknown
CM_ACTIONUPDATE ?
Unknown
CM_ACTIVATE Notification Only
Sent to a form when it becomes the active form.
CM_ALLCHILDRENFLIPPED ?
Sent to a component when the Flip Children|All command in the IDE is executed.
CM_APPKEYDOWN ?
Unknown.
CM_APPSYSCOMMAND ?
Unknown.
CM_BIDIMODECHANGED Notification Only
Sent to a component when it’s BiDiMode property changes.
CM_BORDERCHANGED Notification Only
Sent to a component when it’s Border property changes.
CM_BUTTONPRESSED ?
Unknown.
CM_CHANGED ?
Parameters: TCMCHANGED Return Value: ?.
Unknown.
CM_CHILDKEY ?
Unknown.
CM_CONTROLCHANGE ?
Unknown.
CM_CONTROLLISTCHANGE ?
Parameters: TCMCONTROLCHANGE Return Value: ?.
Unknown.
CM_CTL3DCHANGED Notification Only
Sent to a component when it’s CTL3D property changes.
CM_CURSORCHANGED Notification Only
Sent to a component when it’s Cursor property changes.
CM_DEACTIVATE Notification Only
Sent to a form when it becomes inactive.
CM_DESIGNHITTEST
Parameters: TCMDESIGNHITTEST Return Value: either 0 or 1.
This message is sent in design mode when the mouse
is over the control. It appears that the purpose of the message is to determine
if the control wants to process mouse messages while in design mode. If the return
value is 1 then Delphi lets the control process mouse messages. If it is 0 then
the Delphi handles the messages. If a control sets this message to 1 all the
time then the popup menu will never appear. If the control does not
handle this message or returns 0 all the time then the control cannot response
to mouse messages in design mode.
CM_DIALOGHANDLE ?
Unknown.
CM_DIALOGCHAR ?
Unknown.
CM_DIALOGKEY ?
Unknown.
CM_DOCKCLIENT ?
Parameters: TCMDOCKCLIENT Return Value: ?.
Unknown.
CM_DOCKNOTIFICATION ?
Parameters: TCMDOCKNOTIFICATION Return Value: ?.
Unknown.
CM_DOCWINDOWACTIVATE ?
Unknown.
CM_DRAG ?
Parameters: TCMDRAG Return Value: ?.
Sent to a component when it’s being dragged.
CM_ENABLEDCHANGED NO
Sent to a component when it recieves a WM_ENABLE message.
CM_ENTER ?
Unknown.
CM_EXIT ?
Unknown.
CM_FLOAT ?
Parameters: TCMFLOAT Return Value: ?.
Unknown.
CM_FOCUSCHANGED ?
Parameters: TCMFOCUSCHANGED Return Value: ?.
Unknown.
CM_FONTCHANGED Notification Only
Sent to a component when the it’s Font property changes.
CM_FONTCHANGE Notification Only
Sent to a component when it receives a WM_FONTCHANGE message.
CM_GETDATALINK ?
Unknown.
CM_GOTFOCUS Notification Only
Sent to a component when it receives a WM_SETFOCUS message.
CM_HINTSHOW Notification Only
Sent to a component when it’s hint is shown.
CM_HINTSHOWPAUSE ?
Unknown.
CM_ICONCHANGED ?
Unknown.
CM_INVALIDATE Notification Only
Sent to a control when it needs to be repainted.
CM_INVOKEHELP ?
Unknown.
CM_ISTOOLCONTROL ?
Unknown.
CM_LOSTFOCUS Notification Only
Sent to a component when it receives a WM_KILLFOCUS message.
CM_MENUCHANGED ?
Unknown.
CM_MOUSEENTER Notification Only
Sent to a component when the mouse enters the component’s area and it recieves a WM_MOUSEHOVER message.
CM_MOUSELEAVE Notification Only
Sent to a component when the mouse leaves the component’s area and it recieves a WM_MOUSELEAVE message.
CM_MOUSEWHEEL Notification Only
Parameters: TCMMOUSEWHEEL Return Value: ?.
Sent to a component when it recieves a WM_MOUSEWHEEL message.
CM_PARENTBIDIMODECHANGED Notification Only
Sent to all child components when a parent’s (not Owner’s) BiDiMode property changes. This message is also send when the control is gets a new parent.
CM_PARENTCTL3DCHANGED Notification Only
Sent to all child components when a parent (not Owner) receives a CM_CTL3DCHANGED message. This message is also send when the control is gets a new parent.
CM_PARENTCOLORCHANGED Notification Only
Sent to a component when it’s ParentColor property changes. This message is also sent when the component is read from a stream or gets a new parent.
CM_PARENTFONTCHANGED Notification Only
Sent to all child components when a parent (not Owner) receives a CM_FONTCHANGED message. This message is also send when the control is read from a stream or gets a new parent.
CM_PARENTSHOWHINTCHANGED Notification Only
Sent to a component when it’s ParentShowHint property changes. This message is also sent when the componentis read from a stream or gets a new parent.
CM_RECREATEWND ?
Unknown.
CM_RELEASE ?
Unknown.
CM_SHOWHINTCHANGED Notification Only
Sent to a component when it’s ShowHint property changes.
CM_SHOWINGCHANGED ?
Unknown.
CM_SYSCOLORCHANGE Notification Only
Sent to a component when it recieves a WM_SYSCOLORCHANGE message.
CM_SYSFONTCHANGE Notification Only
Sent to a component when it recieves a WM_SYSFONTCHANGE message.
CM_TABSTOPCHANGED ?
Sent to a comonentn when it’s TabStop property changes.
CM_TEXTCHANGED Notification Only
Unknown.
CM_TIMECHANGE Notification Only
Sent to a component when it receives a WM_TIMECHANGE message.
CM_UIACTIVATE ?
Unknown.
CM_UIDEACTIVATE ?
Unknown.
CM_UNDOCKCLIENT ?
Parameters: TCMUNDOCKCLIENT Return value: ?.
Unknown.
CM_CM_VISIBLECHANGED Notification Only
Sent to a control when it’s Visible property changes.
CM_WANTSPECIALKEY Result value: Cardinal
Sent to a component when a special keys is being handled. These
special keys are VK_TAB, VK_LEFT, VK_RIGHT, VK_UP,
VK_DOWN, VK_RETURN, VK_EXECUTE, VK_ESCAPE and
VK_CANCEL. To receive keystroke messages for these keys you have to handle
the CM_WANTSPECIALKEY messages. The CM_WANTSPECIALKEY allows a much
better way of deciding if you require a special key than responding to the
WM_GETDLGCODE messages.
If the message result is non zero then the key is passed onto the
KeyPress method for you to handle, otherwise it is passed onto the controls
parent form for Delphi’s standard navigation handling. The Delphi standard
navigation is where Delphi handles the Tab, Shift-Tab and arrow key
motion between controls, without needing to use the default Windows dialog
manager at all.
CM_WINDOWHOOK ?
Unknown.
CM_WININICHANGE Notification Only
Parameters: WM_WININICHANGE Return Value: None.
Sent to a component when it receives a WM_SETTINGCHANGE or WM_WININICHANGE message.