OnExit *before* the ActiveControl is changed?

mmikkone
mmikkone used Ask the Experts™
on
TStringGrid's OnExit-event happens only after the form's ActiveControl is changed. Is it possible to write code that is executed before ActiveControl is changed? Somekind of OnExit-event that occurs *before* ActiveControl changes?

I'm not going to even try to explain why I need this behaviour, because the explanation would take a screenfull of text...

Marko
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior developer
Commented:
there is WM_KILLFOCUS command. Control receive this message just before loose focus. Do you need some sample?

There is two possibilities:
1.  write your own component with new event
2. intercept WndProc of component placed on form.

Second way is here:

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
...
  public
    OldWndProc: TWndMethod;
    procedure GridWndProc(var M: TMessage);
  end;

...

procedure TForm1.FormCreate(Sender: TObject);
begin
  OldWndProc := StringGrid1.WindowProc;
  StringGrid1.WindowProc := GridWndProc;
end;


procedure TForm1.GridWndProc(var M: TMessage);
begin
  if M.Msg = WM_KILLFOCUS then
  begin
    // now grid going to loose focus
    // you code here
  end;
  OldWndProc(M);
end;

-----
Igor

Author

Commented:
Thanks! That's just what I need!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial