Solved

CreateObject equivalent

Posted on 2002-07-19
8
475 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now