Link to home
Start Free TrialLog in
Avatar of snells
snells

asked on

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.
Avatar of mocarts
mocarts

must be:
var
  st: IUnknown;

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

wbr, mo.
correction :)
as this is an out parameter then there can be only interface type variable.
mo.
Avatar of snells

ASKER

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.
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.
so all code must be something like:

var
  st: IAnObject; // interface type
begin
  flag := control.A('string', false, st);
  string := st.Title;
end;
Avatar of snells

ASKER

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

... This still brings up the same compile error as before.
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.
Avatar of snells

ASKER

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.

Avatar of snells

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of mocarts
mocarts

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial