You're working much too hard. :-)
Your question asks about clicking the button, but your code indicates sending a tab (VK_TAB). I'm not sure which you're actually wanting to do, so I'll try to address both.
I don't know anything about the TcxDBButtonEdit (or any of the other DevExpress controls), but something like this should work for you (for the tab key):
if (ActiveControl is TcxDBButtonEdit) then
begin
// We know it's a TcxDBButtonEdit, so we can directly cast it
if (TcxDBButtonEdit(ActiveControl).Properties.Buttons.Count > 0) and
(TcxDBButtonEdit(ActiveControl.Properties.Buttons.Items[0].Enabled) then
begin
Key := #0;
Self.SelectNext(ActiveControl, True, True); // See notes below
end;
end;
If you're wanting to actually click the button attached to the edit control, DevExpress support has an article that says that you can do this to invoke the button's click handler (replace the call to SelectNext
above):
if (ActiveControl is TcxDBButtonEdit) then
begin
// We know it's a TcxDBButtonEdit, so we can directly cast it
if (TcxDBButtonEdit(ActiveControl).Properties.Buttons.Count > 0) and
(TcxDBButtonEdit(ActiveControl.Properties.Buttons.Items[0].Enabled) then
begin
Key := #0;
TcxCustomEditAccess(ActiveControl).DoButtonClick(0);
end;
end;
(I clearly can't compile the above code, because I don't have the DevEx controls; the line calling DoButtonClick
is from their article. If the compiler complains about it, you probably need to add the following to your code (right above the method containing the code that uses it is probably the best place):
type
TcxCustomEditAccess = class(TCxCustomEdit);
From the 'Access' part of the name, it looks like the DoButtonClick
might be a protected method of the TcxCustomEdit
. Declaring the interposer class allows you access to the protected method.)
Notes about SelectNext:
From the TWinControl.SelectNext documentation
Moves the input focus from the current child control to the next one in the tab order.
Call SelectNext to move the child control focus. SelectNext selects the first child that follows or precedes CurControl in the tab order and that meets the criteria specified in the other parameters.
The GoForward parameter controls the direction of the search. If GoForward is true, FindNextControl searches forward through the child controls in tab order. If GoForward is false, SelectNext searches backward through the controls. The search wraps past the end of the collection back to CurControl.
The CheckTabStop parameter controls whether the control SelectNext finds must be a tab stop. If CheckTabStop is true, the returned control must have its TabStop property set to true, or the search for the next control continues.
If a child control matches the search criteria, that control obtains the focus. If no such child control is found, the focus remains unchanged.