Solved

COM and late binding

Posted on 2002-04-15
9
211 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:asi
ID: 6944086
the object suppose to be in ICI var ?
0
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 101
delphi popmenu non latine charcters 3 30
Delphi Firemonkey send email on Android 1 38
Using MMsystem To change audio input 1 14
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…

713 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