From 0dc1aff3087d1e6a8c437b72f4e9c44b8b81b84e Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 26 Nov 2011 15:16:13 +0000 Subject: [PATCH] cody: dictionary: free FTimer on IDE close git-svn-id: trunk@33800 - --- .../codetools/ide/codyidentifiersdlg.pas | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/components/codetools/ide/codyidentifiersdlg.pas b/components/codetools/ide/codyidentifiersdlg.pas index 69322fccb8..7496e9c29b 100644 --- a/components/codetools/ide/codyidentifiersdlg.pas +++ b/components/codetools/ide/codyidentifiersdlg.pas @@ -81,6 +81,7 @@ type fCritSec: TRTLCriticalSection; fLoaded: boolean; // has loaded the file fStartTime: TDateTime; + fClosing: boolean; procedure SetIdleConnected(AValue: boolean); procedure SetLoadAfterStartInS(AValue: integer); procedure SetLoadSaveError(AValue: string); @@ -90,6 +91,7 @@ type procedure WaitForThread; procedure OnTimer(Sender: TObject); function StartLoadSaveThread: boolean; + procedure OnIDEClose(Sender: TObject); public constructor Create; destructor Destroy; override; @@ -347,13 +349,13 @@ begin end; if ChangeStamp<>OldChangeStamp then begin - if fTimer=nil then begin + if (fTimer=nil) and (not fClosing) then begin fTimer:=TTimer.Create(nil); fTimer.Interval:=SaveIntervalInS*1000; fTimer.OnTimer:=@OnTimer; end; - //debugln(['TCodyUnitDictionary.OnIdle starting timer: ms=',fTimer.Interval]); - fTimer.Enabled:=true; + if fTimer<>nil then + fTimer.Enabled:=true; end; end; finally @@ -389,7 +391,8 @@ end; procedure TCodyUnitDictionary.OnTimer(Sender: TObject); begin if StartLoadSaveThread then - fTimer.Enabled:=false; + if fTimer<>nil then + fTimer.Enabled:=false; end; function TCodyUnitDictionary.GetFilename: string; @@ -400,6 +403,7 @@ end; function TCodyUnitDictionary.StartLoadSaveThread: boolean; begin Result:=false; + if (Self=nil) or fClosing then exit; if (Application=nil) or (CodyUnitDictionary=nil) then exit; //debugln(['TCodyUnitDictionary.StartLoadSaveThread ',fLoadSaveThread<>nil]); BeginCritSec; @@ -416,6 +420,12 @@ begin fLoadSaveThread.Start; end; +procedure TCodyUnitDictionary.OnIDEClose(Sender: TObject); +begin + fClosing:=true; + FreeAndNil(fTimer); +end; + procedure TCodyUnitDictionary.SetIdleConnected(AValue: boolean); begin if FIdleConnected=AValue then Exit; @@ -459,10 +469,12 @@ begin InitCriticalSection(fCritSec); fQueuedTools:=TAVLTree.Create; CodeToolBoss.AddHandlerToolTreeChanging(@ToolTreeChanged); + LazarusIDE.AddHandlerOnIDEClose(@OnIDEClose); end; destructor TCodyUnitDictionary.Destroy; begin + fClosing:=true; CodeToolBoss.RemoveHandlerToolTreeChanging(@ToolTreeChanged); FreeAndNil(fTimer); WaitForThread;