?
Solved

OCX programming in Delphi

Posted on 2003-03-11
10
Medium Priority
?
412 Views
Last Modified: 2010-04-04
Hi,

following is a sample code written in Vb to access Activex Interface.
Can someone show me how to do the same code in DELPHI (Ver 7).

Thanks

////////////////////////////////////////
Here is the same code in VB

see if this may help ....

/// Declaration

Dim ocxMpvDataObject As CMpvData
Dim ocxRtgObject As CRtg
Dim ocxDbsObject As CDbs
Dim ocxMpvViewIMpvView As ocxMpvViewCtl.IMpvView
Dim ocxRtgIMap As ocxRtg.IMap
Dim ocxRtgIRtg As ocxRtg.IRtg
Dim ocxDbsIMap As ocxDbs.IMap
Dim ocxDbsCDbs As ocxDbs.IDbsCategories
Dim ocxDbsIDbsSearch As ocxDbs.IDbsSearch
Dim ocxMpvDataIMap As ocxMpvData.IMap
Dim ocxMpvDataIMpvDataModels As ocxMpvData.IMpvDataModels
Dim ocxMpvDataIMpvDataHighlights As ocxMpvData.IMpvDataHighlights

//end of declaration

//initialising...

   'Set up cmpvview
   Set ocxMpvViewIMpvView = CMpvView1.Object
   
   'Set up cmpvdata
   Set ocxMpvDataObject = New CMpvData
   Set ocxMpvDataIMap = ocxMpvDataObject
   Set ocxMpvDataIMpvDataModels = ocxMpvDataObject
   Set ocxMpvDataIMpvDataHighlights = ocxMpvDataObject
   'Set up CRtg
   Set ocxRtgObject = New CRtg
   Set ocxRtgIMap = ocxRtgObject
   Set ocxRtgIRtg = ocxRtgObject
   'Set up CDbs
   Set ocxDbsObject = New CDbs
   Set ocxDbsIMap = ocxDbsObject
   Set ocxDbsCDbs = ocxDbsObject
   Set ocxDbsIDbsSearch = ocxDbsObject



// end of initialising


thanks
Sri
0
Comment
Question by:sritharanb
[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
  • 6
  • 4
10 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 8110199
Project | Import Type Library..
Choose one you need from list (if not there, find it with Add.. button and add to registered servers)
Set desired locations of units and components in comp. pallete
Click Install.. to install in Component pallete
or
Click Create Unit.. to create unit you may want to modify.

in your project's unit uses put newly created unit name and work with your activex controls just like native components.

wbr, mo.
0
 

Author Comment

by:sritharanb
ID: 8110505
Hi

I have done all these and the controls are in the form, but cannot see the properties in the interface.
for example properties for ocxMpvDataIMpvDataModels are not visible.

to make those INTERFACE usable in Vb as per the sample, we created and declared objects. I need to know how to do declarations and initialisation of those INTERFACE / OBJECTS in Delphi.

Thanks
Sri


0
 
LVL 9

Expert Comment

by:mocarts
ID: 8110615
can you place somewhere to download units generated by Delphi import? I can't write correct code if I don't know class declarations.

something abstract I can write now:

var
 ocxMpvDataObject: CMpvData;
 ocxRtgObject: CRtg;
 ocxDbsObject: CDbs;
 ocxMpvDataIMap: IMap;
begin
  ocxMpvDataObject := CMpvData.Create(nil);
  ocxRtgObject := CRtg.Create(nil);
  ocxDbsObject := CDbs.Create(nil);
  ocxMpvDataIMap := ocxMpvDataObject; // if CMpvData directly implements IMap
  ocxMpvDataObject.QueryInterface(IMap, ocxMpvDataIMap);  // if not
  // etc.
end;

mo.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sritharanb
ID: 8111555
hi mo,


pls mail me to sri@oosys.co.uk

i will reply to u r mail with units attached.


thanks

sri
0
 
LVL 9

Expert Comment

by:mocarts
ID: 8112259
should be like this:

var
ocxMpvDataObject: TCMpvData;
ocxRtgObject: TCRtg;
ocxDbsObject: TCDbs;
ocxMpvViewIMpvView: IMpvView;
ocxRtgIMap: IMap;
ocxRtgIRtg: IRtg;
ocxDbsIMap: IMap;
ocxDbsCDbs: IDbsCategories;
ocxDbsIDbsSearch: IDbsSearch;
ocxMpvDataIMap: IMap;
ocxMpvDataIMpvDataModels: IMpvDataModels;
ocxMpvDataIMpvDataHighlights: IMpvDataHighlights;


begin
  ocxMpvDataObject := TCMpvData.Create(self);
  ocxMpvDataIMap := ocxMpvDataObject.DefaultInterface;
  ocxMpvDataObject.GetInterface(IID_IMpvDataModels, ocxMpvDataIMpvDataModels);
  ocxMpvDataObject.GetInterface(IID_IMpvDataHighlights, ocxMpvDataIMpvDataHighlights);

  ocxRtgObject := TCRtg.Create(self);
  ocxRtgIMap := ocxRtgObject.DefaultInterface;
  ocxRtgObject.GetInterface(IID_IRtg, ocxRtgIRtg);

  ocxDbsObject := TCDbs.Create(self);
  ocxDbsIMap := ocxDbsObject.DefaultInterface;
  ocxDbsObject.GetInterface(IID_IDbsCategories, ocxDbsCDbs);
  ocxDbsObject.Getinterface(IID_IDbsSearch, ocxDbsIDbsSearch);
end;

but these TLB.pas needs to be reworked as there is duplicate IMap interfaces and you maybe want to implement interfaces directly in classes. to achieve this assignment:

ocxRtgIMap := ocxRtgObject;
ocxRtgIRtg := ocxRtgObject;

don't know exactly how to do it at the moment.. :(
wbr, mo.
0
 
LVL 9

Expert Comment

by:mocarts
ID: 8114872
in my previous comment - instead of GetInterface you sholud use QueryInterface with same parameters. result (HResult) of QueryInterface can be:

S_OK     00000000     No error. In some APIs, S_OK indicates a successful operation with a return value of true.
S_FALSE     00000001     No error, but operation did not produce a useful result. In some APIs, S_FALSE indicates a successful operation with a return value of false.
E_INTERFACE     80004002     Interface not supported.
E_UNEXPECTED     8000FFFF     Catastrophic failure
E_NOTIMPL     80004001     Operation not implemented

mo.
0
 

Author Comment

by:sritharanb
ID: 8117439
hi mo,

thanks for the help sofar, but few problems to sort out.
Declaration part went ok, but i had to comment out the following lines to make the code work.

// ocxMpvDataIMap := ocxMpvDataObject.DefaultInterface;
// ocxRtgIMap := ocxRtgObject.DefaultInterface;
// ocxDbsIMap := ocxDbsObject.DefaultInterface;

also whenever i tried to access the ocxMpvViewIMpvView i get access violation error due to not being initialised. how do i initialise ....

ocxMpvViewIMpvView
ocxMpvDataIMpvDataModels
ocxMpvDataIMpvDataHighlights

thanks

sri



0
 
LVL 9

Expert Comment

by:mocarts
ID: 8118092
 why you had to comment out these lines? was there compiler error message or runtime error?

  you should delete declarations of IMap and IMapDisp from all imported units except ocxMpvView_TLB and place in uses clauses of all modified units this ocxMpvView_TLB unit.

  ocxRtgObject.QueryInterface(..) will never return result as this method queries VCL object not OLE object:( you should use DefaultInterface or protected GetServer method of TOleServer.
  check ConnectKind property - it should be one of - ckRunningOrNew, ckNewInstance, ckRunningInstance.

Set ocxMpvViewIMpvView = CMpvView1.Object
I assume CMpvView1 is TCMpvView on form?

  TCmpvView is TOleControl and we must use OleObject property to access interfaces (or ControlInterface property)
  For TOleServer (TCRtg, TCMpvData and TCDbs) we should use DefaultInterface
  to simplify getting interfaces, you can modify imported units by adding apropriate methods to return those interfaces

ocxMpvViewIMpvView := (IUnknown(CMpvView1.OleObject) as IMpvView);

ocxRtgObject := TCRtg.Create(self);
ocxRtgIMap := ocxRtgObject.DefaultInterface;
ocxRtgIRtg := (ocxRtgObject.DefaultInterface as IRtg);

some kind of tangential information, but I hope you understand something what I write here :)
wbr, mo.


0
 
LVL 9

Accepted Solution

by:
mocarts earned 2000 total points
ID: 8118464
and generally you don't need these IMap interfaces as methods of this interface already implemented by object. you can call methods of IMap directly:

ocxRtgObject := TCRtg.Create(self);
ocxRtgObject.mapOpen(..);

wbr, mo.
0
 

Author Comment

by:sritharanb
ID: 8120961
hi mo,

thanks for the help.

it works fine now.

sri
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

801 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