Solved

COM and late binding

Posted on 2002-04-15
9
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

737 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