Solved

COM and late binding

Posted on 2002-04-15
9
207 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
Comment Utility
Listening, I would like to know that too
0
 
LVL 4

Expert Comment

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

Expert Comment

by:Lee_Nover
Comment Utility
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
Comment Utility
the object suppose to be in ICI var ?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
jep

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

Accepted Solution

by:
TOndrej earned 100 total points
Comment Utility
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
Comment Utility
oopsi :)
0
 
LVL 4

Expert Comment

by:jsweby
Comment Utility
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
Comment Utility
mmm ... nice
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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