|
Ah. I'm sorry I disagree.
Firstly, Andrew wanted to add a TAOleCoordinate to
his TAOleCoordinateList. So the Add() method expected a TAOleCoordinate
parameter, NOT a TAOleCoordinateList parameter.
Secondly, there is no need to always reference
TInterfaceList with an interface.
So the declaration
TMyClass=class(TObject)
private
FInterfaceList :
TInterfaceList;
end;
is fine, provided you NEVER extract an interface
reference to the list object. The reference count in FInterfaceList starts at
zero, when it is created, and remains at zero, and is destroyed with
FInterfaceList.Free().
Conor,
the reason you need to use _AddRef on your
TInterfaceList, is that somewhere in your code you are refering to the internal
list with something like this
procedure SomeMethod()
var
LocalList : IInterfaceList; //interface
variable
begin
MyObject := TMyClass.Create();
LocalList :=
MyObject.FInterfaceList;
// LocalList.Add(AInterface);
....
end;
this extracts an interface reference to
FInterfaceList and increases the reference count to 1. As soon as LocalList goes
out of scope, ie at the end of SomeMethod(), the reference count drops back to
zero and FInterfaceList is destroyed!
Personally, to enforce encapsulation, I think
FInterface should never be accessed directly. You should add methods to your
containing object instead. Like so
TMyClass=class(TObject)
private
FInterfaceList :
TInterfaceList;
public
function Add(AInterface : IInterface) : Integer;
function Remove(AInterface : IInterface) : Integer;
end; Which is what Andrew is doing.
Todd.
----- Original Message -----
|
No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.8.3/361 - Release Date: 11/06/2006
_______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi
