I have an app with a TPageControl on the main form. The pagecontrol has several tabs. The app can be minimized to a tray icon. Sometimes after running minimized for a while, when I restore the main window (via a right-mouse click on the tray icon), the tab that was last displayed is displayed, but I can't select any other tabs!
If I click on another tab, the appearance changes so that tab then appears to be the active one (i.e the tab itself moves to the front of the row of tabs), but the body of the tab remains as it was. I also have menu items and shortcut keys to select the other tabs and they behave the same. If I type Alt-O (options) the options tab at the top becomes active but I can't see what is on the body of that tab - I still see the other tab's contents.
I have verified that focus moves off the first tab when I click on another tab and moves back when I click on that tab.
I haven't yet established if the behaviour is confined to a particular tab as it takes a while for it to happen.
Any ideas?
Update
Interesting note. I have established that the problem occurs under these circumstances. The app is started, then minimized to the tray. An alert condition is detected, pops up a window and restores the main window (this is intended behaviour of the app). It is at this point the fault is observed - i.e. I cant see the other tabs when I click on them.
- Start app. Tab 1 is displayed
- Minimize app. to tray
- Wait for popup to show, main form is restored
- Click on Tab 2 FAULT OBSERVED (Tab 2 body does not display)
- Put breakpoint in TWinControl.CreateHandle
- Click on Tab 3 - breaks
- Run - does not show Tab 3 body
- Click on Tab 1 - does not break
- Click on Tab 3 - does not break
- Click on Tab 4 - breaks
- Run - does not show Tab 4 body
- Click on Tab 1, 2, 3, 4 - does not break
So it seems the tabs are creating their handles the first time they are clicked on, and from that point on they think they exist, but they don't show. If the popup is disabled the fault is not observed. The popup is triggered from an Application.OnIdle task.
Another update: Some progress. After poking around on the web I made some changes.
I removed the following code:
procedure RestoreMainWindow ;
begin
MainForm.WindowState := wsNormal ;
MainForm.visible := true ;
Application.Restore ;
Application.BringToFront ;
ShowWindow (Application.Handle, SW_SHOW) ; { show the taskbar button }
end ;
and replaced it with:
procedure RestoreMainWindow ;
begin
MainForm.Show () ;
MainForm.WindowState := wsNormal ;
Application.BringToFront () ;
ShowWindow (Application.Handle, SW_SHOW) ; { show the taskbar button }
end ;
I removed:
procedure TTADMainForm.SendToTray (Sender: TObject) ;
begin
MainForm.visible := false ;
ShowWindow (Application.Handle, SW_HIDE) ; { hide the taskbar button }
end ;
...
Application.OnMinimize := SendToTray ;
and replaced it with:
procedure TTADMainForm.ApplicationEvents1Minimize(Sender: TObject) ;
begin
Hide();
WindowState := wsMinimized ;
TrayIcon1.Visible := True;
end ;
and the problem seems to have gone. HOWEVER. Now I can minimize the app after startup, the popup occurs and shows modally, the main form shows, all the tabs display and work. BUT. I can't minimize the form again. The OnMinimize handler doesn't get triggered after the first time. Grrrrr.
I still can't fathom why it works now, which is a little worrying. And how do I get it to minimize again??