Re: Delphi interfaces vs. COM interfaces
From: Harley Pebley (harley_pebley_at_idahotech.com)
Date: 12/11/03
- Next message: QHenrick_Hellstr=F6m_=5BStreamSec=5D=22?=: "Re: When random isn't random"
- Previous message: Iain Macmillan: "Re: TLabel-problem (set caption from another window/unit)"
- In reply to: Brad White: "Re: Delphi interfaces vs. COM interfaces"
- Next in thread: Harley Pebley: "Re: Delphi interfaces vs. COM interfaces"
- Reply: Harley Pebley: "Re: Delphi interfaces vs. COM interfaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 10 Dec 2003 16:58:52 -0700
> Or change your function signature so that it takes a const interface
> variable.
>
> Instead of
> function TMyObject.Myfunc(Value: ILockable): Boolean;
> use
> function TMyObject.Myfunc(const Value: ILockable): Boolean;
>
> Delphi passes it a copy so it can't be changed, when the
> function returns, it decrements the reference count of the COPY.
> The original goes on it's merry way.
> The advantage to this method, is that only the function that uses
> the interface has to change. The clients don't even need to be aware
> that they are passing an interface.
In the context of mixing object references and interface references,
counting on the const to not cause an object reference to go out of scope
is pretty dangerous. I wouldn't recommend using it. Reason is, the const
only keeps the reference count from being incremented on entry to the
function and decremented on exit. If the function being called does
anything which would cause the count to change (such as assigning the
parameter to an internal variable, using a with statement, calling another
function with it as a parameter that is not const, etc.), then there will
be problems.
Regards,
Harley Pebley
- Next message: QHenrick_Hellstr=F6m_=5BStreamSec=5D=22?=: "Re: When random isn't random"
- Previous message: Iain Macmillan: "Re: TLabel-problem (set caption from another window/unit)"
- In reply to: Brad White: "Re: Delphi interfaces vs. COM interfaces"
- Next in thread: Harley Pebley: "Re: Delphi interfaces vs. COM interfaces"
- Reply: Harley Pebley: "Re: Delphi interfaces vs. COM interfaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|