I am writing a TStringGrid-based OCX which allows the user to assign a
control (TEdit, TComboBox, TDateTimePicker,..) to a column, allowing the
user to input data into the grid.
Since I have created only one object per column, all rows use the same
Object, resulting in a control only showing in the selected cell. Selecting
a cell containing a TEdit control causes the object to show, and to get
focus (it has a blinking cursor). What should happen is that when the user
starts typing, the entered characters are added to the Edit box (pretty
normal behaviour for an Edit).
This all works fine when I use the control in a Delphi 4 app, but not when
I use is inside another 3rd party development environment (IMA's Edge)
What is happening, is that when the user clicks on a cell the Edit box is
shown, and contains a blinking cursor. However, when the user starts
typing, focus is shifted to the next object on the screen.
When the (still visible, but without a blinking cursor) Edit box is clicked
once again, the cursor is back, and now typed characters _are_ added to the
Edit box.
So when an EditBox (and MaskEdit/Memo/ComboBox) is made visible (in the
Grid's OnDrawCell event), the EditBox acts like it has received focus, but
really hasn't.
This is a trace of the EditBoxes messages I generated using WinSight :
* WinSight message trace Thu Apr 08 1999 17:22:13 *
000091:00000BC0 {TEdit} WM_NCPAINT Sent wp=00000001!
000092:00000BC0 {TEdit} WM_ERASEBKGND Sent hdc 000005FE
> user clicks empty cell, TEdit is made visible :
000093:00000BC0 {TEdit} WM_WINDOWPOSCHANGING Sent (0,0)-(0,0)
Z-Order Top
000094:00000BC0 {TEdit} WM_WINDOWPOSCHANGED Sent (79,58)-(143,82)
NoSize, NoMove, NoZOrder, NoActivate, HideWindow Z-Order Unchanged
000095:00000BC0 {TEdit} WM_WINDOWPOSCHANGING Sent (0,0)-(0,0)
Z-Order Top
000096:00000BC0 {TEdit} WM_WINDOWPOSCHANGED Sent (79,83)-(143,107)
NoSize, NoZOrder, NoRedraw, NoActivate Z-Order Unchanged
000097:00000BC0 {TEdit} WM_MOVE Sent (79,83)
000098:00000BC0 {TEdit} WM_WINDOWPOSCHANGING Sent (0,0)-(0,0)
Z-Order Top
000099:00000BC0 {TEdit} WM_WINDOWPOSCHANGED Sent (79,83)-(143,107)
NoSize, NoMove, NoZOrder, NoActivate, ShowWindow Z-Order Unchanged
000100:00000BC0 {TEdit} WM_SETFOCUS Sent Focus from hwnd 00000D14
000101:00000BC0 {TEdit} WM_GETDLGCODE Sent
000102:00000BC0 {TEdit} WM_NCPAINT Sent wp=00000001!
000103:00000BC0 {TEdit} WM_ERASEBKGND Sent hdc 000005F6
000104:00000BC0 {TEdit} WM_WINDOWPOSCHANGING Sent (0,0)-(0,0)
Z-Order Top
000105:00000BC0 {TEdit} WM_WINDOWPOSCHANGED Sent (79,83)-(143,107)
NoSize, NoMove, NoZOrder, NoActivate, HideWindow Z-Order Unchanged
000106:00000BC0 {TEdit} WM_WINDOWPOSCHANGING Sent (0,0)-(0,0)
Z-Order Top
000107:00000BC0 {TEdit} WM_WINDOWPOSCHANGED Sent (79,83)-(143,107)
NoSize, NoMove, NoZOrder, NoActivate, ShowWindow Z-Order Unchanged
000108:00000BC0 {TEdit} WM_NCPAINT Sent wp=00000001!
000109:00000BC0 {TEdit} WM_ERASEBKGND Sent hdc 000005F6
000110:00000BC0 {TEdit} WM_GETDLGCODE Sent
000111:00000BC0 {TEdit} WM_NCPAINT Sent wp=00000001!
000112:00000BC0 {TEdit} WM_ERASEBKGND Sent hdc 000005FE
> User presses X-key, focus is transferred to next object (handle :
00000DE8)
000113:00000BC0 {TEdit} WM_KEYDOWN Dispatched 58h 88d VK_X Scan 2Dh
Down
000114:00000BC0 {TEdit} WM_KILLFOCUS Sent Focus to hwnd 00000DE8
> User clicks on visible TEdit :
000115:00000BC0 {TEdit} WM_MOUSEACTIVATE Sent LButtonDown in Client
hwnd 0000072C
000116:00000BC0 {TEdit} WM_LBUTTONDOWN Dispatched (26,15) LButton
000117:00000BC0 {TEdit} WM_SETFOCUS Sent Focus from hwnd 00000DE8
000118:00000BC0 {TEdit} WM_LBUTTONUP Dispatched (26,15)
000119:00000BC0 {TEdit} WM_CAPTURECHANGED Sent Capture to 00000000
> User presses X-key, which is added to the contents
000120:00000BC0 {TEdit} WM_KEYDOWN Dispatched 58h 88d VK_X Scan 2Dh
Down
000121:00000BC0 {TEdit} WM_CHAR Dispatched 78h 120d 'x' Scan 2Dh
Down
000122:00000BC0 {TEdit} WM_CHAR Dispatched 78h 120d 'x' Scan 2Dh
Down
000123:00000BC0 {TEdit} WM_KEYUP Dispatched 58h 88d VK_X Scan 2Dh
Up
000124:00000BC0 "x" WM_KILLFOCUS Sent Focus to hwnd 00000000
Can anyone shed some light on the situation, I've run out of ideas...
TIA
ps : please reply to both my e-mail and to the newsgroup
Jeroen Stolting
TeleDynamics B.V.
The Netherlands
How about intercepting either the WM_KEYDOWN or the WM_KILLFOCUS message of
the TEdit box. For some reason the WM_KILLFOCUS is being sent, so if you can
intercept this message, you can decide whether or not to eat this message or
allow it to be passed. You can do this by adding message handlers to the
TEdit control.
Hope this helps,
Martin