Article

From:
To:
Adalberto Baldini
Subject:
Re: SetFocus not working well
Newsgroup:
embarcadero.public.delphi.language.delphi.win32

Re: SetFocus not working well

Adalberto Baldini wrote:

> Peter, yr suggestion works thanks, but explain me why my solution
> doesn't work:
> before Application.Run  both forms MainFrm and Login_Dlg are created,
> when Application.Runs MainFrm.OnActivate event is fired consequently
> after creation sequence ?

Well, "creation sequence" was perhaps not a good choice of term. What
is also involved is making the forms visible.

The creation sequence has basically two "branches". The one which is clearly evident from the code is the VCL object creation, which you refer to above. But forms (like any TWinControl descendent) have API window handles as well, and those are typically created later. The VCL creates handles as late as possible, basically when they are first needed. Setting focus needs a window handle. And a window has to be visible to be able to accept the focus.
That's were it gets fuzzy. OnActivate fires before the form has painted itself to the screen. The VCL has at that point already told Windows to set focus to a control on the form, but that operation has not yet completed since the form is not actually visible on screen yet. Now you come and tell a different form to show itself, which again involves setting the focus, this time to a control on the new form. And since the first focus transition has not completed yet Windows gets confused and you end up with no focus anywhere.


-- Peter Below (TeamB) Don't be a vampire (http://slash7.com/pages/vampires), use the newsgroup archives : http://codenewsfast.com http://groups.google.com
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Sun, 30 Jun 2024 18:20:59 UTC
Copyright © 2009-2024
HREF Tools Corp.