Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Not Allowed in Variant Dispatch Call

Status
Not open for further replies.

saif

Programmer
Mar 28, 2001
47
Hi

I have problem in calling my COM object. I made a COM object in which i define a record

REC = packed record
wsGtc: WideString;
wsSender: WideString;
wsMsgType: WideString;
wsMsgRef: WideString;
wsHotelCode: WideString;
wsHotelVedor: WideString;
wsPayingPPL: WideString;
wsXAdult: WideString;
wsXChild: WideString;
wsBEDAdult: WideString;
wsBedChild: WideString;
wsXCribs: WideString;
wsCheckInDate: WideString;
wsCheckOutDate: WideString;
wsNoOfRooms: WideString;
end;


In COM Method (function Encode(var HACRec: REC; out ErrorRec: ErrorRecord): PChar; safecall;), I passed this parameter as HAC*.

The problem arises when i am trying to call this method from my delphi application. I am calling this metod as

procedure TForm1.EncodeClick(Sender: TObject);
var
crs: REC;
encode: variant;
a: PChar;
ErrorRec: ErrorRecord;
begin
crs.sGtc := 'H';
crs.sSender := 'H';
crs.sMsgType := 'mtHotelAvailability_Req';
crs.sMsgRef := 'HA';

crs.sHotelCode := 'ABCDEF';
crs.sHotelVedor := 'ZE';
crs.sPayingPPL := '1';
crs.sNoOfRooms := '3';

crs.sXAdult := '0';
crs.sXChild := '0';
crs.sBEDAdult := '0';
crs.sBedChild := '0';
crs.sXCribs := '0';

crs.sCheckInDate := '02AUG0000';
crs.sCheckOutDate := '25AUG0000';

encode := CreateOleObject('Mycom.EncodeRequest');

//Error Line
a := encode.Encode(crs, ErrorRec);
Memo1.Text := String(a);

end;

So this function gives me error "Type Not Allowed in Variant Dispatch Call" on this line
a := encode.Encode(crs, ErrorRec);

Hope I will get solution soon
Thanks
Saif
 
Citing Delphi help file : "A method declared in a dispatch interface cannot contain directives other than dispid. Parameter and result types must be automatable—that is, they must be Byte, Currency, Real, Double, Longint, Integer, Single, Smallint, AnsiString, WideString, TDateTime, Variant, OleVariant, WordBool, or any interface type.".
Hope that would help you to find a solution soon ;)

--- markus
 
Can you please also tell me how can I pass Pointer of a record if i use IDispatch interface


Thanks
Saif
 
Can you please also tell me how can I pass Pointer of a record if i use IDispatch interface


Thanks
Saif
 
I am not really good in OLE automation, but here some ideas: any pointer is a number after all so you cast it to LongInt and pass it as LongInt to your COM object. In your COM object, after recieving it you'll cast it to a pointer to you record. For example your COM method could look like
function Encode(var HACRec : LongInt): PChar; safecall
begin
pREC(HACRec)^.blahbla := SomeValue;
...
end;

and call to that method look like :
a := Encode.Encode(LongInt(@crs));

That's what i think though. Maybe other guys will be able to help you more.
Good luck.

--- markus
 
In this style it is giving me error, "Incompatible types: Varaint and PChar" during caompilation time. So please provide me its solution.

thanks
Saif(saifurab@yahoo.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top