2 Replies - 4661 Views - Last Post: 20 September 2010 - 12:48 AM Rate Topic: -----

#1 Guest_Goldie*


Reputation:

Delphi: How to get an access to Idispatch member of idispatch interfac

Posted 11 September 2010 - 09:24 PM

Hi everyone. I am a physicist. I am trying to work on Delphi with an imported activex control (ocx file). There are 3 automation interfaces in the library: IGraph, IGraphAxes and IAxis. The structure of the library is such that:

===IGraph’s properties:===
Idispatch* IGraphAxes;
... //other members

===IGraphAxes’ properties:===
Idispatch* XAxis;
Idispatch* YAxis;
Idispatch* ZAxis;
integer Color;
integer Style;
… //other members

===IAxis properties:===
float Min, Max;
Boolean ShowNumbers;
… //other members

From IGraph, I am able to get an access to simple members of IGraphAxes (Color and Style) using GetIDsOfNames() and Invoke() functions. But when I try to get an access to XAxis (or YAxis, Zaxis) it generates an error. First, I use GetIDsOfNames() and it returns the dispid of XAxis without any problem. But when I call Invoke with that dispid there is an error “Access violation at address …”. It seems, the idispatch pointer Xaxis points to nothing. How can I solve this? How to make
Idispatch* Xaxis
and
IAxis interface attached to each other?

P.S. Sorry for my english. I'm not a native speaker.

Is This A Good Question/Topic? 0

Replies To: Delphi: How to get an access to Idispatch member of idispatch interfac

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Delphi: How to get an access to Idispatch member of idispatch interfac

Posted 13 September 2010 - 03:31 PM

Hi,

The purpose of an interface is to define a set of variable, properties and methods that a class that inherits the interface to use and implement those entities. An interface cannot be instantiated and the methods do not contain any code(if you are familiar with C++, it's like a header file). So, what you have to do is to create classes that implement those interfaces and write your own logic.


TGraph = class(IGraph)
     Idispatch* IGraphAxes;
public 
    constructor Create();
//    other procedures and functions
// private function and procedures
end;


Was This Post Helpful? 0
  • +
  • -

#3 Guest_Goldie*


Reputation:

Re: Delphi: How to get an access to Idispatch member of idispatch interfac

Posted 20 September 2010 - 12:48 AM

Hi. Thanks for your reply. Actually the activex control is a third-party visual component for plotting some 3d graphics. When I import the ocx file into Delphi, it appears on the ActiveX tab of the Component Palette. I just drag it with mouse and put on a form and an object
 Graph1:  TGraph;

is automatically added to my code. Its properties and events become visible in the Object Inspector window. Now I want to get an access to the control’s axes from my code. As you can see, the property <Idispatch * IGraphAxes> represents coordinate axes. Also I guess that IGraphAxes’ XAxis/YAxis/ZAxis members are idispatch pointers of type IGraphAxis. I wrote the following procedures to access an idispatch interface:

procedure TForm2.GetProperty(dispobj: IDispatch; PropertyName: WideString;
                                var retvalue: Variant; Sender: TObject);
var hr: HRESULT;
    DispId: integer;
    value: Variant;
    params: TDispParams;
begin
  hr:=dispobj.GetIDsOfNames(GUID_NULL,@PropertyName, 1, LOCALE_SYSTEM_DEFAULT, @DispId);
  Label1.Caption:=inttostr(DispId);
  hr:=dispobj.Invoke(DispId,GUID_NULL,LOCALE_SYSTEM_DEFAULT,DISPATCH_PROPERTYGET,
                  Params,@Value,nil,nil);
  Retvalue:=Value;
  Label2.Caption:=inttostr(value);
end;

procedure TForm2.SetProperty(dispobj: IDispatch; PropertyName: WideString; Value: OLEVariant;
                                Sender: TObject);
var 
    hr: HRESULT;
    DispId: integer;
    params: TDispParams;
begin
   hr:=dispobj.GetIDsOfNames(GUID_NULL,@PropertyName,1, LOCALE_SYSTEM_DEFAULT, @DispId);
  Label1.Caption:=inttostr(DispId);
  params.rgvarg:=@Value;
  params.rgdispidNamedArgs:=@DispIDArgs;
  params.cArgs:=1;
  params.cNamedArgs:=1;
  hr:=dispobj.Invoke(DispId,GUID_NULL,LOCALE_SYSTEM_DEFAULT,
                  DISPATCH_PROPERTYPUT,Params,nil,nil,nil);
 end;


They work fine with Color and Style properties of IGraphAxes:
GetProperty(Graph1.GraphAxes, 'Color', retvalue, Sender);

Or
SetProperty(Graph1.GraphAxes, 'Color',value,Sender);


But how to get full access to XAxis/YAxis/ZAxis members of IGraphAxes?
Was This Post Helpful? 0

Page 1 of 1