From 7d13839a556e0950fe8ccf74a7d0526cfe36535d Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 22 Jun 2005 07:24:07 +0000 Subject: [PATCH] + Added TFPObjectList implementation from Ales Katona git-svn-id: trunk@470 - --- fcl/inc/contnrs.pp | 108 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/fcl/inc/contnrs.pp b/fcl/inc/contnrs.pp index c081c33d81..05abd4525e 100644 --- a/fcl/inc/contnrs.pp +++ b/fcl/inc/contnrs.pp @@ -21,6 +21,28 @@ uses SysUtils,Classes; Type +{$inline on} + + TFPObjectList = class(TFPList) + private + FFreeObjects : Boolean; + protected + function GetItem(Index: Integer): TObject; {$ifdef HASINLINE} inline;{$endif} + procedure SetItem(Index: Integer; AObject: TObject); {$ifdef HASINLINE} inline;{$endif} + public + constructor Create; + constructor Create(FreeObjects : Boolean); + function Add(AObject: TObject): Integer; {$ifdef HASINLINE} inline;{$endif} + function Extract(Item: TObject): TObject; + function Remove(AObject: TObject): Integer; + function IndexOf(AObject: TObject): Integer; + function FindInstanceOf(AClass: TClass; AExact: Boolean; AStartAt: Integer): Integer; + procedure Insert(Index: Integer; AObject: TObject); {$ifdef HASINLINE} inline;{$endif} + function First: TObject; + function Last: TObject; + property OwnsObjects: Boolean read FFreeObjects write FFreeObjects; + property Items[Index: Integer]: TObject read GetItem write SetItem; default; + end; TObjectList = class(TList) private @@ -131,6 +153,92 @@ Type implementation +constructor TFPObjectList.Create(FreeObjects : boolean); +begin + inherited Create; + FFreeObjects:=Freeobjects; +end; + +constructor TFPObjectList.Create; +begin + inherited Create; + FFreeObjects:=True; +end; + +function TFPObjectList.GetItem(Index: Integer): TObject; {$ifdef HASINLINE} inline;{$endif} +begin + Result:=TObject(inherited Get(Index)); +end; + +procedure TFPObjectList.SetItem(Index: Integer; AObject: TObject); {$ifdef HASINLINE} inline;{$endif} +var + O : TObject; +begin + if OwnsObjects then + begin + O:=GetItem(Index); + O.Free; + end; + Put(Index,Pointer(AObject)); +end; + +function TFPObjectList.Add(AObject: TObject): Integer; {$ifdef HASINLINE} inline;{$endif} +begin + Result:=inherited Add(Pointer(AObject)); +end; + +function TFPObjectList.Extract(Item: TObject): TObject; +begin + Result:=Tobject(inherited Extract(Pointer(Item))); +end; + +function TFPObjectList.Remove(AObject: TObject): Integer; +begin + Result:=inherited Remove(Pointer(AObject)); +end; + +function TFPObjectList.IndexOf(AObject: TObject): Integer; +begin + Result:=inherited indexOF(Pointer(AObject)); +end; + +function TFPObjectList.FindInstanceOf(AClass: TClass; AExact: Boolean; AStartAt : Integer): Integer; +var + I : Integer; +begin + I:=AStartAt; + Result:=-1; + If AExact then + while (I