Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CreateObject equivalent

Posted on 2002-07-19
8
Medium Priority
?
480 Views
Last Modified: 2010-04-04
Greetings, all!

Suppose I have following VB code:

dim foo as ISomeInterface
set foo = createobject("SomeProgId")
foo.someMethod

How do I make such thing in Delphi?

I've imported DLL that contains ISomeInterface.

Respectfully yours, Eugene.
0
Comment
Question by:eugenem
[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
8 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 400 total points
ID: 7165659

One way to get the same functionality:

include ComObj in the uses

var
 foo: ISomeInterface;
begin

 foo:=CreateOleObject('SomeProgId') as ISomeInterface;
 // Or...
 // foo:=CreateComObject(StringToGUID('SomeProgId')) as ISomeInterface;
 foo.someMethod();
 foo:=nil;

end;

Russell
0
 
LVL 3

Author Comment

by:eugenem
ID: 7166333
All right, now I have following trouble:

var
  progId : string;
  classId : TGUID;
  foo : IUnknown;
begin
  try
    progId := 'testEventHandler.test';
    classId := ProgIdToClassId( progId );
    foo := CreateComObject( classId );
    fHandler := foo as IwwaMOSEventHandler;
  except
  end;
end;

CreateComObject throws EOleSysError exception with text: 'OLE error 800A0196'.
CreateObject in VB does work perfectly. Server is written in VB as well.

Any ideas?
0
 
LVL 3

Expert Comment

by:smurff
ID: 7169256
listening
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:Russell Libby
ID: 7169460

I haven't got a clue without having the COM server to test against...

It should be noted that the CreateComObject() function does nothing but call CoCreateInstance. (which is what VB is doing under the covers in a CreateObject call). The result code returned is not standard (one of the expected OLE HResults), and I have found no reference to that code, either in the MSDN or on the net.

Russell

0
 
LVL 3

Author Comment

by:eugenem
ID: 7170231
Interesting...

I make simplest COM server ever: project with one class with one method (Project1.Class1).

Then if I create it in VB, I get good object and can call this method using late binding.

In Delphi I get nil.
0
 
LVL 3

Author Comment

by:eugenem
ID: 7380381
anybody?
0
 

Expert Comment

by:CleanupPing
ID: 9343028
eugenem:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9461314
eugenem,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to rllibby http:#7165659

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

704 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