<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
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.....<br>
<br>
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.<br>
<br>
Phil.<br>
<br>
Todd Martin wrote:
<blockquote cite="mid00ab01c68e79$2acf3f10$896f96ca@p2400" type="cite">
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <meta content="MSHTML 6.00.2900.2873" name="GENERATOR">
  <style></style>
  <div><font face="Arial" size="2">Ah. I'm sorry I disagree.</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Firstly, Andrew wanted to add a
TAOleCoordinate to his&nbsp;TAOleCoordinateList. So the Add() method
expected a TAOleCoordinate parameter,&nbsp;NOT a TAOleCoordinateList
parameter.</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Secondly, there&nbsp;is no need to always
reference TInterfaceList with an interface.</font></div>
  <div><font face="Arial" size="2">So the declaration</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">TMyClass=class(TObject)</font></div>
  <div><font face="Arial" size="2">private</font></div>
  <div><font face="Arial" size="2">&nbsp; FInterfaceList : TInterfaceList;</font></div>
  <div><font face="Arial" size="2">end;</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">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().</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Conor, </font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">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</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">procedure SomeMethod()</font></div>
  <div><font face="Arial" size="2">var</font></div>
  <div><font face="Arial" size="2">&nbsp; LocalList : IInterfaceList;
//interface variable</font></div>
  <div><font face="Arial" size="2">begin</font></div>
  <div><font face="Arial" size="2">&nbsp; MyObject := TMyClass.Create();</font></div>
  <div><font face="Arial" size="2">&nbsp; LocalList :=
MyObject.FInterfaceList;</font></div>
  <div><font face="Arial" size="2">//&nbsp; LocalList.Add(AInterface);</font></div>
  <div><font face="Arial" size="2">....</font></div>
  <div><font face="Arial" size="2">end;</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">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!</font></div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Personally, to enforce
encapsulation, I think FInterface should never be accessed directly.
You should add methods to your containing object instead. Like so</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">
  <div><font face="Arial" size="2">TMyClass=class(TObject)</font></div>
  <div><font face="Arial" size="2">private</font></div>
  <div><font face="Arial" size="2">&nbsp; FInterfaceList : TInterfaceList;</font></div>
  <div>public</div>
  <div>&nbsp; function Add(AInterface : IInterface) : Integer;</div>
  <div>&nbsp; function Remove(AInterface : IInterface) : Integer;</div>
  <div><font face="Arial" size="2">end;</font></div>
  </font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Which is what Andrew is doing.</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Todd.</font></div>
  <div>&nbsp;</div>
  <div>----- Original Message ----- </div>
  <blockquote
 style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
    <div
 style="background: rgb(228, 228, 228) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>From:</b>
    <a title="phil@tumonz.co.nz" href="mailto:phil@tumonz.co.nz">Phil
Middlemiss</a> </div>
    <div
 style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>To:</b>
    <a title="delphi@ns3.123.co.nz" href="mailto:delphi@ns3.123.co.nz">NZ
Borland Developers Group - Delphi List</a> </div>
    <div
 style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Sent:</b>
Tuesday, June 13, 2006 9:42 AM</div>
    <div
 style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Subject:</b>
Re: [DUG] (no subject)</div>
    <div><br>
    </div>
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.<br>
    <br>
eg,<br>
    <br>
TMyObject = class(TObject)<br>
private<br>
&nbsp; FInterfaceList : IInterfaceList;<br>
public<br>
&nbsp; constructor create;<br>
end;<br>
    <br>
constructor TMyObject.create;<br>
begin<br>
&nbsp; FInterfaceList := TInterfaceList; // automatic typecast to
IInterfaceList<br>
end;<br>
    <br>
Conor Boyd wrote:
    <blockquote
 cite="mid8285CB7241FCFC4BB721A6F953F9B35E04A66206@nzc-ap-xch-01.ap.trimblecorp.net"
 type="cite">
      <meta content="MSHTML 6.00.2900.2873" name="GENERATOR">
      <div dir="ltr" align="left"><span class="117441421-12062006"><font
 color="#0000ff" face="Arial" size="2">Can you clarify that for me?</font></span></div>
      <div dir="ltr" align="left"><span class="117441421-12062006"></span>&nbsp;</div>
      <div dir="ltr" align="left"><span class="117441421-12062006"><font
 color="#0000ff" face="Arial" size="2">Why does it *need* to be
referenced with an IInterfaceList?</font></span></div>
      <div dir="ltr" align="left"><span class="117441421-12062006"></span>&nbsp;</div>
      <div dir="ltr" align="left"><span class="117441421-12062006"><font
 color="#0000ff" face="Arial" size="2">I've just started using a
&nbsp;TInterfaceList to hold references to interfaces, but I don't see why I
have to use interfaces WRT the list itself?</font></span></div>
      <div dir="ltr" align="left"><span class="117441421-12062006"></span>&nbsp;</div>
      <div dir="ltr" align="left"><span class="117441421-12062006"><font
 color="#0000ff" face="Arial" size="2">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.&nbsp; Could these two things be
related?</font></span></div>
      <div dir="ltr" align="left"><span class="117441421-12062006"></span>&nbsp;</div>
      <div dir="ltr" align="left"><span class="117441421-12062006"><font
 color="#0000ff" face="Arial" size="2">Grateful for your thoughts...</font></span></div>
      <div dir="ltr" align="left"><span class="117441421-12062006"></span>&nbsp;</div>
      <div dir="ltr" align="left"><span class="117441421-12062006"><font
 color="#0000ff" face="Arial" size="2">C.</font></span></div>
      <br>
      <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us">
      <hr tabindex="-1"> </div>
      <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us"><font face="Tahoma"><font size="2"><b>From:</b> <a
 class="moz-txt-link-abbreviated"
 href="mailto:delphi-bounces@ns3.123.co.nz">delphi-bounces@ns3.123.co.nz</a>
[<a class="moz-txt-link-freetext"
 href="mailto:delphi-bounces@ns3.123.co.nz">mailto:delphi-bounces@ns3.123.co.nz</a>]
      <b>On Behalf Of </b>Phil Middlemiss<br>
      <span class="117441421-12062006"><font color="#0000ff"
 face="Arial">&nbsp;</font></span></font></font></div>
      <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us">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.<br>
      <br>
Conor Boyd wrote: </div>
      <blockquote
 cite="mid8285CB7241FCFC4BB721A6F953F9B35E04A661A3@nzc-ap-xch-01.ap.trimblecorp.net"
 type="cite">
        <meta content="MSHTML 6.00.2900.2873" name="GENERATOR">
        <div dir="ltr" align="left"><span class="552015620-12062006"><font
 color="#0000ff" face="Arial" size="2">I'm sure it was just a typo, but
it should be a TInterfaceList instead of a TList.</font></span></div>
        <div dir="ltr" align="left"><span class="552015620-12062006"></span>&nbsp;</div>
        <div dir="ltr" align="left"><span class="552015620-12062006"><font
 color="#0000ff" face="Arial" size="2">Cheers,</font></span></div>
        <div dir="ltr" align="left"><span class="552015620-12062006"></span>&nbsp;</div>
        <div dir="ltr" align="left"><span class="552015620-12062006"><font
 color="#0000ff" face="Arial" size="2">Conor</font></span></div>
        <br>
        <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us">
        <hr tabindex="-1"> </div>
        <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us"><font face="Tahoma"><font size="2"><b>From:</b> <a
 class="moz-txt-link-abbreviated"
 href="mailto:delphi-bounces@ns3.123.co.nz">delphi-bounces@ns3.123.co.nz</a>
[<a class="moz-txt-link-freetext"
 href="mailto:delphi-bounces@ns3.123.co.nz">mailto:delphi-bounces@ns3.123.co.nz</a>]
        <b>On Behalf Of </b>Phil Middlemiss<br>
        <span class="552015620-12062006"><font color="#0000ff"
 face="Arial">&nbsp;</font></span></font></font></div>
        <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us"><font face="Tahoma"><font size="2"><span
 class="552015620-12062006"></span></font></font><font face="Tahoma"><font
 size="2"><span class="552015620-12062006"><font face="Arial" size="2">[snip]</font>
        </span></font></font></div>
        <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us"><span class="552015620-12062006"></span>&nbsp;</div>
        <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us">You should also be adding it to an IInterfaceList instead
of a TList.<br>
        <br>
        <p><font face="Arial" size="2">[snip]</font> </p>
        </div>
      </blockquote>
      <pre wrap=""><hr size="4" width="90%">
_______________________________________________
Delphi mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a>
<a class="moz-txt-link-freetext"
 href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a>
  </pre>
    </blockquote>
    <p> </p>
    <hr> _______________________________________________<br>
Delphi mailing list<br>
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a><br>
<a class="moz-txt-link-freetext" href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a><br>
    <p> </p>
    <hr> No virus found in this incoming message.<br>
Checked by AVG Free Edition.<br>
Version: 7.1.394 / Virus Database: 268.8.3/361 - Release Date:
11/06/2006<br>
  </blockquote>
  <pre wrap="">
<hr size="4" width="90%">
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
  </pre>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Delphi mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a>
<a class="moz-txt-link-freetext" href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a>
  </pre>
</blockquote>
</body>
</html>