diff --git a/debugger/watchesdlg.pp b/debugger/watchesdlg.pp index 15a4cead8c..43b0ec430c 100644 --- a/debugger/watchesdlg.pp +++ b/debugger/watchesdlg.pp @@ -155,6 +155,7 @@ type procedure DoItemRemovedFromView(Sender: TDbgTreeView; AnItem: TObject; ANode: PVirtualNode); procedure DoUnLockCommandProcessing(Data: PtrInt); + procedure DoWatchFreed(Sender: TObject); function GetWatches: TIdeWatches; procedure ContextChanged(Sender: TObject); procedure SnapshotChanged(Sender: TObject); @@ -920,11 +921,26 @@ begin DebugBoss.UnLockCommandProcessing; end; +procedure TWatchesDlg.DoWatchFreed(Sender: TObject); +var + nd: PVirtualNode; +begin + nd := tvWatches.FindNodeForItem(Sender); + if nd = nil then + exit; + + tvWatches.OnItemRemoved := nil; + tvWatches.NodeItem[nd] := nil; + tvWatches.OnItemRemoved := @DoItemRemovedFromView; +end; + procedure TWatchesDlg.DoItemRemovedFromView(Sender: TDbgTreeView; AnItem: TObject; ANode: PVirtualNode); begin - if AnItem <> nil then + if AnItem <> nil then begin TWatch(AnItem).ClearDisplayData; + TWatch(AnItem).RemoveFreeNotification(@DoWatchFreed); + end; end; procedure TWatchesDlg.DoBeginUpdate; @@ -1623,6 +1639,7 @@ begin then begin VNode := tvWatches.AddChild(nil, AWatch); tvWatches.SelectNode(VNode); + AWatch.AddFreeNotification(@DoWatchFreed); end; UpdateItem(VNode, AWatch); diff --git a/ide/packages/idedebugger/idedebuggerbase.pas b/ide/packages/idedebugger/idedebuggerbase.pas index 945fd09b2a..443191d311 100644 --- a/ide/packages/idedebugger/idedebuggerbase.pas +++ b/ide/packages/idedebugger/idedebuggerbase.pas @@ -5,10 +5,11 @@ unit IdeDebuggerBase; interface uses - Classes, SysUtils, LazClasses, LazLoggerBase, IdeDebuggerWatchResult, - IdeDebuggerBackendValueConv, IdeDebuggerWatchResultJSon, DbgIntfDebuggerBase, - DbgIntfMiscClasses, LazDebuggerIntf, LazDebuggerTemplate, - LazDebuggerIntfBaseTypes, LazDebuggerValueConverter, FpDebugConvDebugForJson; + Classes, SysUtils, LazClasses, LazLoggerBase, LazMethodList, + IdeDebuggerWatchResult, IdeDebuggerBackendValueConv, + IdeDebuggerWatchResultJSon, DbgIntfDebuggerBase, DbgIntfMiscClasses, + LazDebuggerIntf, LazDebuggerTemplate, LazDebuggerIntfBaseTypes, + LazDebuggerValueConverter, FpDebugConvDebugForJson; type @@ -112,6 +113,7 @@ type TWatch = class(TDelayedUdateItem) private + FFreeNotificationList: TMethodList; FFirstIndexOffs: Int64; FDbgBackendConverter: TIdeDbgValueConvertSelector; @@ -146,6 +148,9 @@ type destructor Destroy; override; procedure ClearValues; virtual; procedure ClearDisplayData; // keep only what's needed for the snapshot + + procedure AddFreeNotification(ANotification: TNotifyEvent); + procedure RemoveFreeNotification(ANotification: TNotifyEvent); public property Enabled: Boolean read FEnabled write SetEnabled; property Expression: String read FExpression write SetExpression; @@ -622,7 +627,12 @@ begin FDbgBackendConverter.RemoveFreeNotification(@FDbgBackendConverterFreed); FValueList.Clear; + + if FFreeNotificationList <> nil then + FFreeNotificationList.CallNotifyEvents(Self); + inherited Destroy; + FreeAndNil(FFreeNotificationList); FreeAndNil(FValueList); end; @@ -636,6 +646,20 @@ begin FValueList.ClearDisplayData; end; +procedure TWatch.AddFreeNotification(ANotification: TNotifyEvent); +begin + if FFreeNotificationList = nil then + FFreeNotificationList := TMethodList.Create; + FFreeNotificationList.Add(TMethod(ANotification)); +end; + +procedure TWatch.RemoveFreeNotification(ANotification: TNotifyEvent); +begin + if FFreeNotificationList = nil then + exit; + FFreeNotificationList.Remove(TMethod(ANotification)); +end; + { TWatches } function TWatches.GetItemBase(const AnIndex: Integer): TWatch;