c++ - ActiveX differences between Delphi 7 and Delphi XE4 in an MFC application -


when create activex control based on tpanel (with no added code) in delphi 7, able add mfc c++ application , have run fine.

when take exact same code , compile in delphi xe4 (and xe2), mfc throws assertion. confirmed changes in dcu, ocx , res files.

the assertion happening on assert(wflags == dispatch_method); in occsite.cpp (i included source this).

stdmethodimp colecontrolsite::xeventsink::invoke(     dispid dispid, refiid, lcid, unsigned short wflags,     dispparams* pdispparams, variant* pvarresult,     excepinfo* pexcepinfo, unsigned int* puargerror) {     unused(wflags);      method_prologue_ex(colecontrolsite, eventsink)     assert(pthis->m_pctrlcont != null);     assert(pthis->m_pctrlcont->m_pwnd != null);     assert(wflags == dispatch_method);      afx_event event(afx_event::event, dispid, pdispparams, pexcepinfo,         puargerror);      pthis->onevent(&event);      if (pvarresult != null)         ::variantclear(pvarresult);      return event.m_hresult; } 

the value of wflags dispatch_method | dispatchpropertyget.

everything seems work correctly after (mouse events cause similar issues if start in xe4, d7 doesn't include them).

i tried in both visual studio 2010 , visual studio 2012. in mfc, creating new mfc dialog application, right clicking , selecting add activex control. relatively new mfc doing wrong.

the host system in win 7 x64 system.

i can't leave assertions in code , want work correctly can reuse bunch of delphi code in future.

any ideas happening or can point me in better direction head banging on keyboard?

update: 2013.09.18

remy's answer below correct, here more information.

as of xe4, seems primary issues events sent control host (i.e. onclickevent, onmouseenter, onmouseleave, onconstrainedresize, oncanresize or onresizeevent).

i found 3 possible solutions (will update again if find anymore):

  1. comment out code calling these events (i didn't solutions).
  2. comment out lines in comobjs.dispatchinvoke causing set.
  3. modify comobjs have alternate dispatchinvoke , dispcallbyid
    • the alternate dispcallid needs call alternate dispatchinvoke.
    • the alternate dispatchinvoke needs have code changing flag removed
    • the global variable dispcallbyidproc needs set alternate dispcallbyid procedure when being used event.
    • dispcallbyidproc needs set afterward being set alternative (i first line in alternate dispcallbyid).

i used following surround event being called:

fevents <> nil try     setdispatchbycallid(true);     fevents.onclick;     setdispatchbycallid(false); end; 

the time dispatch_method , dispatch_propertyget allowed specified if caller calling invoke() because callee has both method , property have same name. in case, colecontrolsite::xeventsink allow invoked method. simple fix on xevensink side - change assert(wflags == dispatch_method) assert(wflags & dispatch_method) instead. why delphi invoke xeventsink way, thing can find in delphi uses flags following logic in dispatchinvoke() function of comobj unit:

procedure dispatchinvoke(const dispatch: idispatch; calldesc: pcalldesc;   dispids: pdispidlist; params: pointer; result: pvariant); var   ..., invkind: integer;   ... begin   ...   invkind := calldesc^.calltype;   ...   if invkind = dispatch_propertyput   begin     ...   end   else if (invkind = dispatch_method) , (calldesc^.argcount = 0) , (result <> nil)       invkind := dispatch_method or dispatch_propertyget; // <-- here    ...   status := dispatch.invoke(..., invkind, ..., result, ...);   ... end; 

however, logic exists in dispatchinvoke() going way delphi 5, @ least. maybe argcount not 0 or result nil in earlier versions under same conditions xe4 object using? hard sure, dispatchinvoke() gets called in bunch of different places throughout rtl, have track through call stack find out calling xeventsink , why caller specifying particular flag combination.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -