Hi!
I have known problem with keeping focus on focused control in forms mebeded on to TAdvOfficePage -s oo MainForms advOfficePager.
Same concept make me troubles with using action-list shortcuts, but I solved this problem with overriding main form's IsShortCut method.
I overriding Screen.OnActiveControlChange and seting private field with value of screen.active control and filtering captured control class types.
Do You have any known solution for solving this (known vcl/windows) bug? I tryed to use AdvFocusHelper.ShowFocus but with no sucess. On form's page schange selected/active form doesn't fire OnActiavte, OnShow, etc. but self focuses on to some toolbars button.
Any idea?
Thanks!
I'm not sure I understand your problem. Did you try to set the focus programmatically from the TAdvOfficePager.OnChange event? If a problem persists, could you provide some sample source app with which we can reproduce this?
In embeded form I capturing a focused control with Screen.OnActiveControlChange and this works ok.
Creating new inherited form and page on pager is dinamic. after creating I can use form as self-existing form, form as modal form, and form embeded at pager's page. When is embeded i dinamicaly create new page at pager and linking it to form as parent. For this (form)parent page I dinamic create OnShow event from code. In OnShow (of parented page) I check if is assigned my "oldFocusedWinControl) and try to focus this control. At this point sometime was occured error, focused control or controls-parent (some groupbox, panel, etc.) is invisible. I can check oldfocusedWinControl.CanFocus but then focus goes automatically to first selectable control at form (some TButton).
In other words, at time of form parent AdvPage.OnShow fireing some of embeded form's controls are invisible and control can't be focused.
Problem solved!
In focus capturing procedure now i use:
var
tmpKontrola : TWinControl;
tmpForma : TForm;
begin
tmpKontrola := Screen.ActiveControl;
tmpForma := Screen.ActiveForm;
if Assigned (tmpKontrola)and Assigned(tmpForma) then
if (tmpKontrola.Owner = Self) and // <- this is key condition
(tmpKontrola is TWinControl) and
not (tmpKontrola is TAdvOfficePage) and
not (tmpKontrola is TAdvOfficePager) and
not (tmpKontrola is TAdvGlowButton) and
not (tmpKontrola is TForm)
then
begin
fFokusKontrol := tmpKontrola;
end;
if Assigned(OldScreenOnActiveControlChange) then
OldScreenOnActiveControlChange(Sender);
end;
In Main form:
procedure TfrmMain.advpageChange(Sender: TObject);
var
aktivnaForma : TfrmIPStandardForm;
aktivnaKartica : TAdvOfficePage;
begin
inherited;
aktivnaKartica := advpage.AdvPages[advpage.ActivePageIndex];
aktivnaForma := aktivnaKartica.Controls[0] as TfrmIPStandardForm;
aktivnaForma.FokusirajKontrolu;
end;
In embeded form class
function TfrmIPStandardForm.FokusirajKontrolu: boolean;
begin
Result := False;
if not Assigned(fFokusKontrol) then Exit(False);
if not fFokusKontrol.CanFocus then Exit(False);
FokusiranaKontrola.SetFocus;
end;
Finally, its works! key is in checking control's owner and using pager's OnChange instead page's OnShow.
Bruno, thanks a lot on replay!