Solved

COM and late binding

Posted on 2002-04-15
9
208 Views
Last Modified: 2010-04-04
Hello,
I"m making a product for company that give me COM object to connect to there services.
The problem is that this company produce from time to time new COM object with different interface / GUID
So My program have to be very dynamic and load the COM object on run-time (Late binding) and not at startup (in compile time (pre-binding).
My question how can i do it - late binding with COM object ?
 example would be wellcome.

thank u
Asi
0
Comment
Question by:asi
9 Comments
 
LVL 1

Expert Comment

by:pede
ID: 6941923
Listening, I would like to know that too
0
 
LVL 4

Expert Comment

by:nestorua
ID: 6942937
HI, asi,
You have that COM object and registered it, didn't you?
Sincerely,
Nestorua.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6943305
var ICI: ICustomInterface;
begin
  if CoCreateInstance(CLSID_CustomInterface, nil, CLSCTX_INPROC, IID_CustomInterface, ICI) = S_OK then ...

where ICustomInterface is the interface
CLSID_CustomInterface it's class id
IID_CustomInterface it's interface id

you need all these three from the creator of the COM object
0
 

Author Comment

by:asi
ID: 6944086
the object suppose to be in ICI var ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6944582
jep

to free it simply set ICI:=nil;
0
 
LVL 8

Accepted Solution

by:
TOndrej earned 100 total points
ID: 6944611
Lee_Nover, what you've shown is called early binding: the compiler has to know the declaration of ICustomInterface.

Late binding is most simply done via Variant variables (containing reference to IDispatch interface).

Quick example from the help:
Object Pascal Language Guide
"Accessing Automation objects (Windows only)"

var
  Word: Variant;
begin
  Word := CreateOleObject('Word.Basic');
  Word.FileNew('Normal');
  Word.Insert('This is the first line'#13);
  Word.Insert('This is the second line'#13);
  Word.FileSaveAs('c:\temp\test.txt', 3);
end;

With this approach, the compiler knows nothing about 'Word.Basic' object and compiles any properties or method calls, assuming you know what you're doing ;-)

Include ComObj to your uses clause.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6944748
oopsi :)
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6947183
TOndrej is right. The idea behind Late Binding is that the compiler knows nothing of the target COM object and so doesn't try to verify your syntax. This gives you the enormous advantage of being able to code for the object without even actually having it present anywhere, although you would obviously need to know the data structures, the parameters for methods, etc.

The obvious disadvantage of this is that if you get it wrong in your code then you won't know until you run the application.

If COM object changes then you've got another advantage & disadvantage; the advantage being that if it changes things outside of your scope then you don't have to change your application. However, if it does then your application would still compile and run but fall over at execution of the COM object.

The Word example above is a perfect example of what you're after as it is small and often used.

J.
0
 

Author Comment

by:asi
ID: 6953189
mmm ... nice
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now