BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HOWTO: Implement an interface by delegation?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Ian Boyd
Guest





PostPosted: Fri Sep 08, 2006 10:32 pm    Post subject: HOWTO: Implement an interface by delegation? Reply with quote



//i have a base object, and a newly created interface
TShape = class(TObject)
procedure Dummy;
end;

IBottle = interface(IDispatch)
procedure Drink; safecall;
end;

{I want to create a descendant of TShape that implements IBottle
i've actually created my own object that implements IDispatch for various
good reasons
and i want to delegate the handling of IDispatch to that child object:}

TCustomDispatchThingy = class(TObject, IUnknown, IDispatch)
public
function QueryInterface(const IID: TGUID; out Obj): HResult;
stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;

function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo):
HResult; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount,
LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID:
Integer; Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer):
HResult; stdcall;
end;

{Now i'm all set to create my descendant from the ancestor, and say that it
implements the required interfaces:}
TBottleShape = class(TShape, IUnknown, IDispatch, IBottle)
private
FDispatchHandler: TCustomDispatchThingy;
public
procedure Drink; safecall;

property UnknownHandler: TCustomDispatchThingy read FDispatchHandler
implements IUnknown;
property DispatchHandler: TCustomDispatchThingy read
FDispatchHandler implements IDispatch;
end;

But i get the errors here:
Undeclared identifier: 'GetTypeInfoCount'
Undeclared identifier: 'GetTypeInfo'
Undeclared identifier: 'GetIDsOfNames'
Undeclared identifier: 'Invoke'
Undeclared identifier: 'QueryInterface'
Undeclared identifier: '_AddRef'
Undeclared identifier: '_Release'

NOTES
(1) TShape is locked, it cannot descend from anything else or change
(2) IBottle is locked, it cannot descend from any other interface



EXTRA QUESTION:

If IBottle descends from IDispatch, why do i have to list IDispatch again?
TBottleShape = class(TObject, IBottle, IDispatch)

i realize that if i had done:
TBottleShape = class(TAutoIntfObject, IBottle)

i would not have to list IDispatch again, because it comes in with
TAutoIntfObject. But why not the former syntax?

What does it mean in Delphi for an interface to descend from another if that
is never honored? What does it mean? What does it get me? Would

IBottle1 = interface(IDispatch)

be any different from
IBottle2 = interface(IUnknown)

Since in both cases i have to say:
TBottle1 = class(TObject, IUnknown, IDispatch, IBottle1)
TBottle2 = class(TObject, IUnknown, IBottle2)

Is there such a thing in Delphi as interfaces descending from one another?
Isn't

IBottle = interface(IFooDummyGarbageName)
and
IBottle = interface
identical?

What does the former give me that the later doesn't?
Back to top
Marc Rohloff [TeamB]
Guest





PostPosted: Sat Sep 09, 2006 5:22 am    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote



On Fri, 8 Sep 2006 13:32:47 -0400, Ian Boyd wrote:

Quote:
But i get the errors here:
Undeclared identifier: 'GetTypeInfoCount'
....


Which class are you getting the errors on? Find the definition for
IDispatch and IUnknown and make sure that the method specifications
match.

Quote:
If IBottle descends from IDispatch, why do i have to list IDispatch again?
TBottleShape = class(TObject, IBottle, IDispatch)
This is just the way Delphi implements interfaces. You don't have to

list IDispatch, but if you don't then you cannot typecast your
interface to IDispatch.

Quote:
What does it mean in Delphi for an interface to descend from another if that
is never honored? What does it mean? What does it get me? Would
It would mean that anyone who has a reference using the IBottle

interface can call all it's methods without doing a further typecast.
In most cases this isn't what you want (They don't really care about
GetTypeInfo, AddRef, etc) and I would use

Quote:
IBottle2 = interface ...

Is there such a thing in Delphi as interfaces descending from one another?
Yes


Quote:
Isn't
IBottle = interface(IFooDummyGarbageName)
and
IBottle = interface
identical?
No


Quote:
What does the former give me that the later doesn't?
All the methods in IFooDummyGarbageName without a further typecast.


--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Back to top
Ian Boyd
Guest





PostPosted: Wed Sep 13, 2006 12:19 am    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote



Quote:
It would mean that anyone who has a reference using the IBottle
interface can call all it's methods without doing a further typecast.
In most cases this isn't what you want (They don't really care about
GetTypeInfo, AddRef, etc) and I would use

So if i define some interfaces interface
type
IRohloff = interface
public
function GetRace: Integer;
end;

IMark = interface(IRohloff)
public
function GetFingerPrints: OleVariant;
end;

Then on the object
TMarkRohloff = class(TInterfacedObject, IMark)

i can call
MarkRohloff.GetFingerPrints;
and
MarkRohloff.GetRace;

But the MarkRohloff doesn't support IRohloff?


i think this sounds like my problem...

Consider:
TMarkRohloff = class(TInterfacedObject, IMark, IRohloff)
public
function GetFingerPrints: OleVariant;
function GetRace: Integer;
end;


There is now a duplicated method:
IRohloff.GetRace
and
IMark.GetRace

Does Delphi transparently make IMark.GetRace and IRohloff.GetRace use the
same method?
Back to top
Marc Rohloff [TeamB]
Guest





PostPosted: Wed Sep 13, 2006 5:10 am    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote

On Tue, 12 Sep 2006 15:19:18 -0400, Ian Boyd wrote:

Quote:
But the MarkRohloff doesn't support IRohloff?
No it doesn't, although you can access the IRohloff methods from an

IMarc (Please note the important spelling here, An IMark interface
will *never* work for you)


Quote:
There is now a duplicated method:
IRohloff.GetRace
and
IMark.GetRace

Does Delphi transparently make IMark.GetRace and IRohloff.GetRace use the
same method?
Yes


--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Back to top
Ian Boyd
Guest





PostPosted: Wed Sep 13, 2006 11:34 pm    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote

Quote:
Does Delphi transparently make IMark.GetRace and IRohloff.GetRace use the
same method?
Yes

Soooooo damn tricky. Sooooo damn subtle. Soooooo little documentation.


Sorry about the name typo Smile
Back to top
Marc Rohloff [TeamB]
Guest





PostPosted: Thu Sep 14, 2006 7:31 am    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote

On Wed, 13 Sep 2006 14:34:06 -0400, Ian Boyd wrote:

Quote:
Soooooo damn tricky. Sooooo damn subtle. Soooooo little
documentation.

Yes, COM is largely a black art. I would recommend
Delphi COM Programming by Eric Harmon (http://tinyurl.com/h5zt2)

--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Back to top
Dennis Passmore
Guest





PostPosted: Thu Sep 14, 2006 5:12 pm    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote

Quote:

Yes, COM is largely a black art. I would recommend
Delphi COM Programming by Eric Harmon (http://tinyurl.com/h5zt2)


Another good book was
Delphi Developer's Guide to COM+ by Alexander Rodygin.
It was a free download from
http://www.softinterop.com/Home.aspx/dev/bookcomplus
for a long time but I do not think it is online any more.
I have the download "BookCOMPlus.zip" if someone needs it.
Back to top
Ian Boyd
Guest





PostPosted: Thu Sep 14, 2006 11:33 pm    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote

Quote:
Yes, COM is largely a black art. I would recommend
Delphi COM Programming by Eric Harmon (http://tinyurl.com/h5zt2)

Have it, read it.

Also have Don Box's book.
Back to top
Ian Boyd
Guest





PostPosted: Thu Sep 14, 2006 11:34 pm    Post subject: Re: HOWTO: Implement an interface by delegation? Reply with quote

Quote:
Another good book was
Delphi Developer's Guide to COM+ by Alexander Rodygin.
It was a free download from
http://www.softinterop.com/Home.aspx/dev/bookcomplus
for a long time but I do not think it is online any more.
I have the download "BookCOMPlus.zip" if someone needs it.

i don't need a book on COM+ for Delphi, i need a book on what COM+ is.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.