Solved

COM and late binding

Posted on 2002-04-15
9
209 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 265
FMX enumerated colours 2 99
Performance of SQL statement 37 111
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 66
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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