petershaw9
asked on
How to avoid OnKeyDown fires OnExit procedure
I write codes in the Edit box OnExit event and OnKeyDown event. the OnKeyDown procedure likes
begin
if Key = VK_F4 then
F4AutoClick(CmbDeptFrom, edtDeptFrom);
end
Problem is when I press F4, it fires OnExit procedure first, but I don't want OnExit fired. How can I solve the problem? Thanks.
Peter Shaw9
begin
if Key = VK_F4 then
F4AutoClick(CmbDeptFrom, edtDeptFrom);
end
Problem is when I press F4, it fires OnExit procedure first, but I don't want OnExit fired. How can I solve the problem? Thanks.
Peter Shaw9
If all else fails, you could set a boolean variable to true in the onKeyDown handler like this:
if Key = VK_F4 then begin
IgnoreNextOnExit := true;
F4AutoClick(...);
end;
Then in the OnExit handler you could do this:
if IgnoreNextOnExit then begin
IgnoreNextOnExit := false;
exit;
end;
... // rest of the code of OnExit
Regards, Madshi.
if Key = VK_F4 then begin
IgnoreNextOnExit := true;
F4AutoClick(...);
end;
Then in the OnExit handler you could do this:
if IgnoreNextOnExit then begin
IgnoreNextOnExit := false;
exit;
end;
... // rest of the code of OnExit
Regards, Madshi.
peter:
if (Yourform.keypreview=true) and(yourfo rmonkeydow n.ishandle d) then begin
yourform.keydown;
youredit.keydown;
end;
....
Perhaps,the problem is in yourform.keydown.
menxin
if (Yourform.keypreview=true)
yourform.keydown;
youredit.keydown;
end;
....
Perhaps,the problem is in yourform.keydown.
menxin
ASKER
The F4Autoclick is:
procedure TfrmSupport.F4AutoClick(Cm Box : TComboBox; dbEdt : TdbEdit);
var i, Ix : integer;
begin
With CmBox do begin
Ix := -1 ;
With Items do
for i := 0 to Count -1 do
if copy(Items[i], 1, 3) = copy(dbEdt.Text, 1, 3) then
Ix := i ;
ItemIndex := Ix;
SetFocus;
end;
KeyBd_Event(Vk_F4,0,0,0);
KeyBd_Event(Vk_F4,0,KEYEVE NTF_KeyUp, 0);
end;
procedure TfrmSupport.F4AutoClick(Cm
var i, Ix : integer;
begin
With CmBox do begin
Ix := -1 ;
With Items do
for i := 0 to Count -1 do
if copy(Items[i], 1, 3) = copy(dbEdt.Text, 1, 3) then
Ix := i ;
ItemIndex := Ix;
SetFocus;
end;
KeyBd_Event(Vk_F4,0,0,0);
KeyBd_Event(Vk_F4,0,KEYEVE
end;
hi peter,
try this little change
procedure TfrmSupport.F4AutoClick(Cm Box : TComboBox; dbEdt :
TdbEdit);
var i, Ix : integer;
begin
With CmBox do begin
Ix := -1 ;
With Items do
for i := 0 to Count -1 do
if copy(Items[i], 1, 3) = copy(dbEdt.Text, 1, 3) then
Ix := i ;
ItemIndex := Ix;
end;
KeyBd_Event(Vk_F4,0,0,0);
KeyBd_Event(Vk_F4,0,KEYEVE NTF_KeyUp, 0);
CmBox.SetFocus; //this line moved, or delete it if not work, as recommended
end;
meikl
try this little change
procedure TfrmSupport.F4AutoClick(Cm
TdbEdit);
var i, Ix : integer;
begin
With CmBox do begin
Ix := -1 ;
With Items do
for i := 0 to Count -1 do
if copy(Items[i], 1, 3) = copy(dbEdt.Text, 1, 3) then
Ix := i ;
ItemIndex := Ix;
end;
KeyBd_Event(Vk_F4,0,0,0);
KeyBd_Event(Vk_F4,0,KEYEVE
CmBox.SetFocus; //this line moved, or delete it if not work, as recommended
end;
meikl
ASKER
I try Kretzschmar way, it works, but the combobox behavior becomes very strange. Now I am using Madshi suggestion. It works properly.
Many thanks everyboby
PeterShaw9
Many thanks everyboby
PeterShaw9
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what does this code?
>F4AutoClick(CmbDeptFrom, edtDeptFrom);
if i press F4 the onexit-event does not appear. i guess, that the F4AutoClick-procedure moves the focus to another control (a button?), which then causes the exit-event of your edit-box
meikl