Solved

CreateObject equivalent

Posted on 2002-07-19
8
479 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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

635 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