mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-24 15:09:13 +02:00
* added FreeObjects property to TFPGObjectList (as known from TObjectList in contnrs)
git-svn-id: trunk@13108 -
This commit is contained in:
parent
8193cd175d
commit
b340822af2
@ -122,6 +122,7 @@ type
|
|||||||
PT = ^T;
|
PT = ^T;
|
||||||
var protected
|
var protected
|
||||||
FOnCompare: TCompareFunc;
|
FOnCompare: TCompareFunc;
|
||||||
|
FFreeObjects: Boolean;
|
||||||
procedure CopyItem(Src, Dest: Pointer); override;
|
procedure CopyItem(Src, Dest: Pointer); override;
|
||||||
procedure Deref(Item: Pointer); override;
|
procedure Deref(Item: Pointer); override;
|
||||||
function Get(Index: Integer): T; {$ifdef CLASSESINLINE} inline; {$endif}
|
function Get(Index: Integer): T; {$ifdef CLASSESINLINE} inline; {$endif}
|
||||||
@ -129,7 +130,7 @@ type
|
|||||||
function ItemPtrCompare(Item1, Item2: Pointer): Integer;
|
function ItemPtrCompare(Item1, Item2: Pointer): Integer;
|
||||||
procedure Put(Index: Integer; const Item: T); {$ifdef CLASSESINLINE} inline; {$endif}
|
procedure Put(Index: Integer; const Item: T); {$ifdef CLASSESINLINE} inline; {$endif}
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create(FreeObjects: Boolean = True);
|
||||||
function Add(const Item: T): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
|
function Add(const Item: T): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
|
||||||
function Extract(const Item: T): T; {$ifdef CLASSESINLINE} inline; {$endif}
|
function Extract(const Item: T): T; {$ifdef CLASSESINLINE} inline; {$endif}
|
||||||
function First: T; {$ifdef CLASSESINLINE} inline; {$endif}
|
function First: T; {$ifdef CLASSESINLINE} inline; {$endif}
|
||||||
@ -142,6 +143,7 @@ type
|
|||||||
procedure Sort(Compare: TCompareFunc);
|
procedure Sort(Compare: TCompareFunc);
|
||||||
property Items[Index: Integer]: T read Get write Put; default;
|
property Items[Index: Integer]: T read Get write Put; default;
|
||||||
property List: PTypeList read GetList;
|
property List: PTypeList read GetList;
|
||||||
|
property FreeObjects: Boolean read FFreeObjects write FFreeObjects;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
generic TFPGInterfacedObjectList<T> = class(TFPSList)
|
generic TFPGInterfacedObjectList<T> = class(TFPSList)
|
||||||
@ -707,9 +709,10 @@ end;
|
|||||||
{* TFPGObjectList *}
|
{* TFPGObjectList *}
|
||||||
{****************************************************************************}
|
{****************************************************************************}
|
||||||
|
|
||||||
constructor TFPGObjectList.Create;
|
constructor TFPGObjectList.Create(FreeObjects: Boolean);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
FFreeObjects := FreeObjects;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPGObjectList.CopyItem(Src, Dest: Pointer);
|
procedure TFPGObjectList.CopyItem(Src, Dest: Pointer);
|
||||||
@ -724,6 +727,7 @@ begin
|
|||||||
{if TObject(Item^) is TInterfacedObject then
|
{if TObject(Item^) is TInterfacedObject then
|
||||||
T(Item^)._Release
|
T(Item^)._Release
|
||||||
else}
|
else}
|
||||||
|
if FFreeObjects then
|
||||||
T(Item^).Free;
|
T(Item^).Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user