• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

What is wrong with this parameter for receiving data from an ActiveX control

In the *_TLB ... is a control function

function A(const s: widestring; b: boolean;
   out object: IDispatch): wordbool; dispid 9;

I define a object (defined in the control as the received data object) in my app to receive data:-

var st: AnObject;

I call it with:-

control:=CreateComObject(......);
flag:=control.A('string',false,st as AnObject);

and I get compile error for the 'st' parameter:-

'Type of actual and formal var parameters must be identical'

Can anybody help as I'm sure there's a simple answer?

Regards,
Steve.
0
snells
Asked:
snells
  • 6
  • 4
1 Solution
 
mocartsCommented:
must be:
var
  st: IUnknown;

as in function declaration or var st must be an object which implements IUnknown interface.

wbr, mo.
0
 
mocartsCommented:
correction :)
as this is an out parameter then there can be only interface type variable.
mo.
0
 
snellsAuthor Commented:
Thanx mo, quick reply.

So I make it:-

var st: IDispatch;

... and then change code to:-

flag:=control.A('string',false,st);
string:=AnObject(st).title;

Is this the right way to do it?

Regards,
Steve.
0
Industry Leaders: 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!

 
mocartsCommented:
no, this will not work anyway.
you should use interface to get Title. check your _TLB for an interface which is implemented (directly or indirectly) by AnObject (take a look how Title is received in AnObject)
mo.
0
 
mocartsCommented:
so all code must be something like:

var
  st: IAnObject; // interface type
begin
  flag := control.A('string', false, st);
  string := st.Title;
end;
0
 
snellsAuthor Commented:
var
 st: IAnObject; // interface type
begin
 flag := control.A('string', false, st);

... This still brings up the same compile error as before.
0
 
mocartsCommented:
control.A('string', false, IUnknown(st));
should compile this line.

but declaration of A is strange with it parameter name object (reserved word).. at least in my D5 function with such parameter name don't compiles.

mo.
0
 
snellsAuthor Commented:
function A(const s: widestring; b: boolean;
  out object: IDispatch): wordbool; dispid 9;

.. is not the real function declaration it's ...

function GetImageIPTC_Info(const ImageName: widestring; FavorPhotoshopIPTC: wordbool;
  out IPTC_Info: IDispatch): wordbool; dispid 9;

... IPTC_Info is an object with methods/props etc.

... and I'm using Delphi7 ... so things may work differently to 5.

0
 
snellsAuthor Commented:
function A(const s: widestring; b: boolean;
  out object: IDispatch): wordbool; dispid 9;

.. is not the real function declaration it's ...

function GetImageIPTC_Info(const ImageName: widestring; FavorPhotoshopIPTC: wordbool;
  out IPTC_Info: IDispatch): wordbool; dispid 9;

... IPTC_Info is an object with methods/props etc.

... and I'm using Delphi7 ... so things may work differently to 5.

0
 
mocartsCommented:
sorry, you must cast to IDispatch (I think you figured out that :)
control.A('string', false, IDispatch(st));

0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now