An ActiveForm will not receive a WM_ACTIVATE message when initializting since WM_ACTIVATE only goes to the top level windows, or in this case, the IE browser window. By sending our own WM_ACTIVATE, we get initial focus set to the ActiveForm, but more importantly, the WMActivate method in TCustomForm calls TCustomForm.SetActive. This in turn, sets the Active property which means that the form has focus. This is important later on, e.g. in TCustomForm.SetActiveControl, the focus will never be set to the ActiveControl.
For example, the code below will do nothing in the default case. It will work fine after you apply the work-around mentioned later on.
var
ParentForm: TCustomForm;
begin
ParentForm := GetParentForm(Self);
ParentForm.ActiveControl := Edit1;
end;
The bad behavior is also apparent when using TPageControl, since TPageControl.ChangeActivePage tries to set the ActiveControl when changing pages.
The simple work-around for this is to call the following in your ActiveForm code:
PostMessage(Handle, WM_ACTIVATE, WA_ACTIVE, 0); Since I use PARAM tags in my OBJECT tag to pass parameters, I am doing this in IPersistPropertyBagLoad method after creating my Delphi form. After doing this, everything is working great.
Thanks to Steve Trefethen for listening to my original vent.