diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2011-04-05 10:10:46 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2011-04-05 10:10:46 +0200 |
commit | a198402e180fa6f8c284b160f0c29348180b0ea7 (patch) | |
tree | 15851f47dd2ac70e5f6091accd4c19af748af6e9 | |
parent | e8c4e7ec1ee4f757be230bf96cbe90fe6ae7e0e0 (diff) | |
download | fpGUI-a198402e180fa6f8c284b160f0c29348180b0ea7.tar.xz |
Fixes a potential AV when ActiveWidget is freed
If the ActiveWidget was freed, the parent never got notified. If focus was
then changed, the parent tried to call ActiveWidget.HandleFocusKill, causing
an access violation.
The toolkit now correctly sets ActiveWidget to nil if it was freed, and as
a extra failsafe, wraps the HandleFocusKill call in a try..except block.
-rw-r--r-- | src/corelib/fpg_widget.pas | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/corelib/fpg_widget.pas b/src/corelib/fpg_widget.pas index fa167c85..d89b6ac4 100644 --- a/src/corelib/fpg_widget.pas +++ b/src/corelib/fpg_widget.pas @@ -275,8 +275,14 @@ begin if InDesigner then Exit; //==> - if FActiveWidget <> nil then - FActiveWidget.HandleKillFocus; + try + if FActiveWidget <> nil then + FActiveWidget.HandleKillFocus; + except + { This is just a failsafe, in case FActiveWidget was not correctly set + in the destructor of TfpgWidget } + FActiveWidget := nil; + end; FActiveWidget := AValue; if FActiveWidget <> nil then FActiveWidget.HandleSetFocus; @@ -507,6 +513,9 @@ begin writeln('TfpgWidget.Destroy [', Classname, '.', Name, ']'); {$ENDIF} HandleHide; + if Owner <> nil then + if (Owner is TfpgWidget) and (TfpgWidget(Owner).ActiveWidget = self) then + TfpgWidget(Owner).ActiveWidget := nil; inherited Destroy; end; |