|
3 | 3 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
4 | 4 | * obtain one at https://mozilla.org/MPL/2.0/
|
5 | 5 | *
|
6 |
| - * Copyright (C) 2005-2024, Peter Johnson (gravatar.com/delphidabbler). |
| 6 | + * Copyright (C) 2005-2025, Peter Johnson (gravatar.com/delphidabbler). |
7 | 7 | *
|
8 | 8 | * Application's main form. Handles the program's main window display and user
|
9 | 9 | * interaction.
|
@@ -522,6 +522,11 @@ TMainForm = class(THelpAwareForm)
|
522 | 522 | /// <summary>Object that manages favourites.</summary>
|
523 | 523 | fFavouritesMgr: TFavouritesManager;
|
524 | 524 |
|
| 525 | + /// <summary>Handles the <c>WM_POWERBROADCAST</c> messages to detect and |
| 526 | + /// respond to hibernation messages.</summary> |
| 527 | + /// <remarks>This is necessary as part of the fix for an obscure bug. See |
| 528 | + /// https://github.com/delphidabbler/codesnip/issues/70</remarks> |
| 529 | + procedure WMPowerBroadcast(var Msg: TMessage); message WM_POWERBROADCAST; |
525 | 530 | /// <summary>Displays view item given by TViewItemAction instance
|
526 | 531 | /// referenced by Sender and adds to history list.</summary>
|
527 | 532 | procedure ActViewItemExecute(Sender: TObject);
|
@@ -1324,7 +1329,6 @@ procedure TMainForm.FormDestroy(Sender: TObject);
|
1324 | 1329 | // fStatusBarMgr MUST be nilled: otherwise it can be called after status bar
|
1325 | 1330 | // control has been freed and so cause AV when trying to use the control
|
1326 | 1331 | FreeAndNil(fStatusBarMgr);
|
1327 |
| - |
1328 | 1332 | end;
|
1329 | 1333 |
|
1330 | 1334 | procedure TMainForm.FormResize(Sender: TObject);
|
@@ -1514,7 +1518,6 @@ procedure TMainForm.InitForm;
|
1514 | 1518 | // Create object to handle compilation and assoicated UI and dialogues
|
1515 | 1519 | fCompileMgr := TMainCompileMgr.Create(Self); // auto-freed
|
1516 | 1520 |
|
1517 |
| - |
1518 | 1521 | // Set event handler for snippets database
|
1519 | 1522 | Database.AddChangeEventHandler(DBChangeHandler);
|
1520 | 1523 |
|
@@ -1582,5 +1585,22 @@ procedure TMainForm.splitVertCanResize(Sender: TObject;
|
1582 | 1585 | Accept := False;
|
1583 | 1586 | end;
|
1584 | 1587 |
|
| 1588 | +procedure TMainForm.WMPowerBroadcast(var Msg: TMessage); |
| 1589 | +begin |
| 1590 | + // Sometimes when the computer is resumed from hibernation the tree view in |
| 1591 | + // the overview frame is destroyed and recreated by Windows. Unfortunately the |
| 1592 | + // IView instances associated with the recreated tree nodes are lost. |
| 1593 | + // Attempting to read those (now nil) IView instances was resulting in an |
| 1594 | + // access violation. |
| 1595 | + case Msg.WParam of |
| 1596 | + PBT_APMSUSPEND: |
| 1597 | + // Get ready for isolation |
| 1598 | + fMainDisplayMgr.PrepareForHibernate; |
| 1599 | + PBT_APMPOWERSTATUSCHANGE: |
| 1600 | + // Restore from hibernation: ensure the IView instances are recreeated |
| 1601 | + fMainDisplayMgr.RestoreFromHibernation; |
| 1602 | + end; |
| 1603 | +end; |
| 1604 | + |
1585 | 1605 | end.
|
1586 | 1606 |
|
0 commit comments