Board index » delphi » SOLVED: By Value Variant Parameters in VC++ ActiveX Control Events

SOLVED: By Value Variant Parameters in VC++ ActiveX Control Events

According to the VC++ documentation, when an ActiveX control wishes to pass
a VARIANT parameter by value in an event, it specifies the type as
VTS_VARIANT and passes the parameter as a const reference.  This is
supposedly distinct from a by reference VARIANT parameter which is passed as
VTS_PVARIANT, and a pointer passed.  Someone somewhere seems to have
forgotten that a const reference _is_ a pointer!

Unfortunately, what this means is that the parameter arrives in the Delphi
event handler as a POINTER.  When the compiler generated event handler
procedure entry code tries to apply _Var System routines to this parameter,
it finds itself confronted with a pointer, and unsurprisingly an exception
is raised.

Fortunately, you can fool the compiler into generating the write code by
manually adding the "const" directive to the parameter in the event handler.

I don't think this could properly be attributed as a Delphi bug, since the
type library generated for the ActiveX control is clearly lying about the
nature of the parameter.  Unless there is a reference somewhere explaining
how all variants are passed by address, even when specified as passed by
value, this seems to me to be a Microsoft fault.

Interestingly, VB has no problem interpreting such an incorrectly described
parameter, suggesting that either this is documented as the correct
behaviour somewhere, or alternatively that Microsoft are up to their usual
tricks of mandating one behaviour for the rest of the world, whilst they
happily make and break their own rules as they go along.

Has anyone ever tried writing a VB event handler for a Delphi sourced event
which does actually pass a VARIANT, rather than a pointer to a variant?  If
so, what happened?

--
Jolyon Smith
Neot Software Services Ltd.
http://www.neot.co.uk

begin 666 Jolyon Smith.vcf
M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..E-M:71H.TIO;'EO;@T*1DXZ
M2F]L>6]N(%-M:71H#0I/4D<Z3F5O="!3;V9T=V%R92!397)V:6-E<R!,=&0N
M#0I4251,13I-86YA9VEN9R!$:7)E8W1O<@T*5$5,.U=/4DL[5D])0T4Z*S0T
M(#$T.# @,S@U-3<Q#0I414P[5T]22SM&05@Z*S0T(#$T.# @,S4Y,#<Y#0I!
M1%([5T]22SH[.SL[0V%M8G)I9&=E<VAI<F4[.U5.251%1"!+24Y'1$]-#0I,
M04)%3#M73U)+.T5.0T]$24Y'/5%53U1%1"U04DE.5$%"3$4Z0V%M8G)I9&=E
M<VAI<F4],$0],$%53DE4...@2TE.1T1/30T*55),.@T*55),.FAT=' Z+R]W
M=W<N;F5O="YC;RYU:PT*14U!24P[4%)%1CM)3E1%4DY%5#IJ<VUI=&A ;F5O
J="YC;RYU:PT*4D56.C(P,# P-S(W5#$S,30U,5H-"D5.1#I60T%21 T*
`
end

 

Re:SOLVED: By Value Variant Parameters in VC++ ActiveX Control Events


Quote
> ...write code...

Ooops.  That should of course read "right code".  <smacks-head>

--
Jolyon Smith
Neot Software Services Ltd.
http://www.neot.co.uk

Other Threads