Hi Phil
 
Yes, I agree TOleCoordinateList should be referenced by interface IOleCoordinateList and TOleCoordinate should be referenced by interface IOleCoodinate, but I was refering to the internal TLIST that Andrew mentioned, which holds the automation objects inside TOleCoordinateList. As Conor pointed out, that should be TInterfaceList. You would only be forced to reference this internal list by interface, if you were exposing it as a public property of TOleCoordinateList, which would be bad practice anyway IMHO.
 
Todd.
 
----- Original Message -----
Sent: Tuesday, June 13, 2006 12:03 PM
Subject: Re: [DUG] (no subject)

True. You could get away with just using a TInterfaceList object. But you would have to be extremely careful to *never* cause it's RefCount to increment/decrement. Which, when you're talking about automation objects seems unlikely if that TAOleCoordinateList is made visible through the automation interfaces. Personally, I find it much easier to just use an IInterfaceList holder - then I never need worry about it. Which is kinda how it's designed after all.....

I know Andrew (not Thomas as I referred to you earlier Andrew - your email shows your last name first) wanted to add a TAOleCoordinate to his list, but I was implying that he should really use an interface from when it is created anyway. To me, trying to handle automation objects as objects and not interfaces just adds a level of complexity that I can do without since automation objects are inevitably going to have their reference count incremented/decremented by the automation client. But I guess if you can safely guarantee that reference counting will never be an issue then go ahead and just use a TInterfaceList.

Phil.

Todd Martin wrote:
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 -----
Sent: Tuesday, June 13, 2006 9:42 AM
Subject: Re: [DUG] (no subject)

TInterfaceList is descended from TInterfacedObject, so it needs to be referenced with an interface to keeps it's reference count above 0 - else it will be destroyed along with all the objects it contains.

eg,

TMyObject = class(TObject)
private
  FInterfaceList : IInterfaceList;
public
  constructor create;
end;

constructor TMyObject.create;
begin
  FInterfaceList := TInterfaceList; // automatic typecast to IInterfaceList
end;

Conor Boyd wrote:
Can you clarify that for me?
 
Why does it *need* to be referenced with an IInterfaceList?
 
I've just started using a  TInterfaceList to hold references to interfaces, but I don't see why I have to use interfaces WRT the list itself?
 
Having said that, I have an issue where I have to explicitly call _AddRef on the interface I'm adding to my interfacelist to keep it alive.  Could these two things be related?
 
Grateful for your thoughts...
 
C.


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Phil Middlemiss
 
No, it wasn't a typo - he needs to *create* a TInterfaceList - but that list needs to be *referenced* with an IInterfaceList. It was intentional to force Thomas to look up how to end up with a working IInterfaceList.

Conor Boyd wrote:
I'm sure it was just a typo, but it should be a TInterfaceList instead of a TList.
 
Cheers,
 
Conor


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Phil Middlemiss
 
[snip]
 
You should also be adding it to an IInterfaceList instead of a TList.

[snip]


_______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi


_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.8.3/361 - Release Date: 11/06/2006

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


_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.8.3/361 - Release Date: 11/06/2006
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

Reply via email to