From d1b209025f7f6071ff39a1404aac9590d7b0d289 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 22 Mar 2012 12:10:06 +0000 Subject: [PATCH] * Applied patch from Luiz Amerigo to have Delphi compatible behaviour when freeing a stringlist (bug 21529) git-svn-id: trunk@20570 - --- rtl/objpas/classes/classesh.inc | 1 + rtl/objpas/classes/stringl.inc | 46 ++++++++++++++++----------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/rtl/objpas/classes/classesh.inc b/rtl/objpas/classes/classesh.inc index e804d180e2..556f0d870b 100644 --- a/rtl/objpas/classes/classesh.inc +++ b/rtl/objpas/classes/classesh.inc @@ -679,6 +679,7 @@ type FOwnsObjects : Boolean; procedure ExchangeItems(Index1, Index2: Integer); procedure Grow; + procedure InternalClear; procedure QuickSort(L, R: Integer; CompareFn: TStringListSortCompare); procedure SetSorted(Value: Boolean); procedure SetCaseSensitive(b : boolean); diff --git a/rtl/objpas/classes/stringl.inc b/rtl/objpas/classes/stringl.inc index 021b33e202..7bc4ff58ce 100644 --- a/rtl/objpas/classes/stringl.inc +++ b/rtl/objpas/classes/stringl.inc @@ -908,7 +908,28 @@ begin SetCapacity(NC); end; +Procedure TStringList.InternalClear; +Var + I: Integer; + +begin + if FOwnsObjects then + begin + For I:=0 to FCount-1 do + begin + Flist^[I].FString:=''; + freeandnil(Flist^[i].FObject); + end; + end + else + begin + For I:=0 to FCount-1 do + Flist^[I].FString:=''; + end; + FCount:=0; + SetCapacity(0); +end; Procedure TStringList.QuickSort(L, R: Integer; CompareFn: TStringListSortCompare); var @@ -1128,13 +1149,8 @@ end; destructor TStringList.Destroy; -Var I : Longint; - begin - FOnChange:=Nil; - FOnChanging:=Nil; - Clear; - SetCapacity(0); + InternalClear; Inherited destroy; end; @@ -1156,26 +1172,10 @@ end; Procedure TStringList.Clear; -Var I : longint; - begin if FCount = 0 then Exit; Changing; - if FOwnsObjects then - begin - For I:=0 to FCount-1 do - begin - Flist^[I].FString:=''; - freeandnil(Flist^[i].FObject); - end; - end - else - begin - For I:=0 to FCount-1 do - Flist^[I].FString:=''; - end; - FCount:=0; - SetCapacity(0); + InternalClear; Changed; end;