Solved

CreateObject equivalent

Posted on 2002-07-19
8
474 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

13 Experts available now in Live!

Get 1:1 Help Now