 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Os2 Guest
|
Posted: Tue Dec 16, 2003 10:45 am Post subject: what is DispInterface? |
|
|
what is actualy DispInterface?
when can i use it?
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Tue Dec 16, 2003 4:25 pm Post subject: Re: what is DispInterface? |
|
|
<
what is actualy DispInterface?
Short answer: it is a specification for an IDispatch
interface.
Long answer: The IDispatch interface is the basis of all
automation. It has two methods that allow pointerless
scripting languages to call methods by name, instead of
using method pointers: GetIDsOfNames, and Invoke.
GetIdsOfNames retrieves the numerical ID of a method with a
given name (provided that the object implements another
interface that has method with that name). Invoke uses the
numerical ID of a method to call that method. The numerical
ID of a method is called the dispid.
For example, suppose you create an interface that looks
like this:
IMyIntf = interface(IDispatch)
['{4D733280-C514-11D4-8481-A68F52CBDB56}']
procedure DoThis;
end;
and an object that implements it that looks like this:
TMyDispatchObj = class(TAutoObject, IMyIntf)
public
procedure DoThis;
end;
Delphi will call both GetIDSOfNames and Invoke for you -
all you need to do is use a variant. Like this:
AVar: OleVariant;
..
AVar := CreateComObject(CLASS_TMyAutoObj) as IDispatch;
AVar.DoThis;
Every time you call a method of an variant referencing an
IDispatch interface, GetIDsOfNames and Invoke are called
for you behind the scenes.
However, calling GetIdsOfNames for every method is quite
slow. And since all it does is find a numerical ID for a
given method name, it might be nice if you could look up
that ID in advance and pass it to Invoke directly, rather
than go through GetIdsOfNames every time. Enter the
dispinterface:
IMyDispInterface = dispinterface
['{4D733284-C514-11D4-8481-A68F52CBDB56}']
procedure DoThis; dispid 1;
end;
This declaration tells Delphi the dispid of each method in
an interface. So if you use a dispinterface variable,
rather than a variant, Delphi can call Invoke directly
using that, rather than go through GetIdsOfNames:
var
Disp: IDispatch;
Dispint: IMyDispInterface;
..
Disp := CreateComObject(CLASS_TMyAutoObj) as IDispatch;
Dispint := IMyDispInterface(Disp);
Dispint.DoThis;
A dispinterface is not a true interface. When you use a
dispinterface, you are actually using the IDispatch
interface of an object, just as you are when you use a
variant. That's why you can cast an IDispatch interface
directly to a dispinterface, as in the second line above.
All you're doing here is telling the compiler that you
already know what other methods a particular object will
implement, and what dispids can be used to invoke
them with.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
| Back to top |
|
 |
Os2 Guest
|
Posted: Tue Dec 16, 2003 5:43 pm Post subject: Re: what is DispInterface? |
|
|
Ok. thanks.
but i still dont understand something.
in order to use the dispInterface i need to add the *_TLB.pas to the uses
clause of my client (to have the DispInterfce definition).
so if i use that file in the uses clause of my client - I can "early bind"
with the interface itself instead of the dispinterface, and to save the same
time.
so where is the benefit?
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.00001deb.00b688d2 (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Os2:
what is actualy DispInterface?
Short answer: it is a specification for an IDispatch
interface.
Long answer: The IDispatch interface is the basis of all
automation. It has two methods that allow pointerless
scripting languages to call methods by name, instead of
using method pointers: GetIDsOfNames, and Invoke.
GetIdsOfNames retrieves the numerical ID of a method with a
given name (provided that the object implements another
interface that has method with that name). Invoke uses the
numerical ID of a method to call that method. The numerical
ID of a method is called the dispid.
For example, suppose you create an interface that looks
like this:
IMyIntf = interface(IDispatch)
['{4D733280-C514-11D4-8481-A68F52CBDB56}']
procedure DoThis;
end;
and an object that implements it that looks like this:
TMyDispatchObj = class(TAutoObject, IMyIntf)
public
procedure DoThis;
end;
Delphi will call both GetIDSOfNames and Invoke for you -
all you need to do is use a variant. Like this:
AVar: OleVariant;
.
AVar := CreateComObject(CLASS_TMyAutoObj) as IDispatch;
AVar.DoThis;
Every time you call a method of an variant referencing an
IDispatch interface, GetIDsOfNames and Invoke are called
for you behind the scenes.
However, calling GetIdsOfNames for every method is quite
slow. And since all it does is find a numerical ID for a
given method name, it might be nice if you could look up
that ID in advance and pass it to Invoke directly, rather
than go through GetIdsOfNames every time. Enter the
dispinterface:
IMyDispInterface = dispinterface
['{4D733284-C514-11D4-8481-A68F52CBDB56}']
procedure DoThis; dispid 1;
end;
This declaration tells Delphi the dispid of each method in
an interface. So if you use a dispinterface variable,
rather than a variant, Delphi can call Invoke directly
using that, rather than go through GetIdsOfNames:
var
Disp: IDispatch;
Dispint: IMyDispInterface;
.
Disp := CreateComObject(CLASS_TMyAutoObj) as IDispatch;
Dispint := IMyDispInterface(Disp);
Dispint.DoThis;
A dispinterface is not a true interface. When you use a
dispinterface, you are actually using the IDispatch
interface of an object, just as you are when you use a
variant. That's why you can cast an IDispatch interface
directly to a dispinterface, as in the second line above.
All you're doing here is telling the compiler that you
already know what other methods a particular object will
implement, and what dispids can be used to invoke
them with.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Tue Dec 16, 2003 6:23 pm Post subject: Re: what is DispInterface? |
|
|
<
so if i use that file in the uses clause of my client - I
can "early bind" with the interface itself instead of the
dispinterface, and to save the same time.
so where is the benefit?
None there - if you can use the real interface, you
generally should. But not all type libraries expose those,
so sometimes the dispinterface is the best you can do.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
| Back to top |
|
 |
|
|
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
|
|