Solved

CreateObject equivalent

Posted on 2002-07-19
8
476 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 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