You have another problem with your current implementation: The reference counting of your interfaces will not work. You have to call manually the _AddRef and _Release of the interface after adding them to the list and removing them. You also can't use FList.Clear, because then the reference counting doen't work either.
Am Samstag, den 09.09.2006, 20:10 -0300 schrieb Cesar Romero:
Can someone suggest a better way to do that?
Now Im using:
THashedInterfaceList = class(TInterfacedObject, IHashedInterfaceList)
private
FList: THashedStringList;
protected
function Add(const Name: string; const Item: IInterface): Integer;
function GetCount: Integer;
function GetItem(const Name: string): IInterface;
function GetItems(const Index: Integer): IInterface;
function IndexOf(const Name: string): Integer;
function IndexOfItem(const Item: IInterface): Integer;
procedure Clear;
procedure Delete(const Index: Integer);
property Item[const Name: string]: IInterface read GetItem;
property Items[const Index: Integer]: IInterface read GetItems; default;
property Count: Integer read GetCount;
public
constructor Create(const SortList: boolean = False); virtual;
destructor Destroy; override;
end;
function THashedInterfaceList.Add(const Name: string;
const Item: IInterface): Integer;
begin
Result:= FList.AddObject(Name, Pointer(Item));
end;
procedure THashedInterfaceList.Clear;
begin
FList.Clear;
end;
constructor THashedInterfaceList.Create(const SortList: boolean);
begin
inherited Create;
FList:= THashedStringList.Create;
FList.Duplicates:= dupError;
FList.Sorted:= SortList;
end;
procedure THashedInterfaceList.Delete(const Index: Integer);
begin
FList.Delete(Index);
end;
destructor THashedInterfaceList.Destroy;
begin
FList.Free;
inherited;
end;
function THashedInterfaceList.GetCount: Integer;
begin
Result:= FList.Count;
end;
function THashedInterfaceList.GetItem(const Name: string): IInterface;
begin
Result:= Items[IndexOf(Name)];
end;
function THashedInterfaceList.GetItems(const Index: Integer): IInterface;
var
LItem: Pointer;
begin
if (Index <> NotFound) and (Index < Count) then
LItem:= FList.Objects[Index]
else
LItem:= nil;
Result:= IInterface(LItem);
end;
function THashedInterfaceList.IndexOf(const Name: string): Integer;
begin
Result:= FList.IndexOf(Name);
end;
function THashedInterfaceList.IndexOfItem(const Item: IInterface): Integer;
begin
Result:= FList.IndexOfObject(Pointer(Item));
end;
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives
