ActiveX lazarus / 34-Windows ---------------------------------------------------------------------- LA.Center · 2011-09-08 22:48 I am successfully creating WebBrowser ActiveX Control on my form, I Sink the events and can catch all events that are fired. But what I can't figure out is: In the BeforeNavigate event DispID = 100 you can Cancel the navigation which is the param at position 0 (reversed); Does anyone know how to pass ByRef params to a X Object using EventSink? I have attached also a demo project, and my TActiveX component, feel free to use it if you like. I actually found the X Object embedding part in this forum but I changed it into a component. ---------------------------------------------------------------------- LA.Center · 2011-09-09 17:19 Guess no one here uses ActiveX -> should have thought so. But any ideas are welcome too. ---------------------------------------------------------------------- joseme · 2011-12-06 04:21 Hi. I am working on a project that uses ActiveX, I am interested in your demo, butI cannot download it. Can you please send me a copy? Thanks! ---------------------------------------------------------------------- joseme · 2011-12-06 04:26 Dont send me the file, finally my browser was able to get it. Thanks! ---------------------------------------------------------------------- LA.Center · 2011-12-06 06:46 the component changed a bit, Params needs to be a pointer then you can set also var params, in case you have not figured it out, let me know I will post TActiveX component again. ---------------------------------------------------------------------- ludob · 2011-12-06 07:59 Quote from: plusplus on September 09, 2011, 07:19:27 pmGuess no one here uses ActiveX -> should have thought so. But any ideas are welcome too. Is your initial problem solved? I posted the original DemoAX and EventSink on the lazarus mailing list back in May QuoteDoes anyone know how to pass ByRef params to a X Object using EventSink?An EventSink only receives data. ---------------------------------------------------------------------- LA.Center · 2011-12-06 08:07 I actually did not solve it, one of our programmers seems to has solved it with pointers, @parms value where he writes the value directly into the address of the given parameter. It seems to be working, I can send a true value to the Cancel parameter in the BeforeNavigateEvent for example. ---------------------------------------------------------------------- ludob · 2011-12-06 11:53 Quote from: plusplus on December 06, 2011, 09:07:55 amI actually did not solve it, one of our programmers seems to has solved it with pointers, @parms value where he writes the value directly into the address of the given parameter. It seems to be working, I can send a true value to the Cancel parameter in the BeforeNavigateEvent for example. OK. For posterity, the solution is: Code: [Select]Params.rgvarg[0].pbool^:=OleVariant(true); ---------------------------------------------------------------------- Sora-Kun · 2011-12-06 17:37 Thanks for sharing, but is it only for Windows ? I don't know a lot about ActiveX, but I guess yes. ---------------------------------------------------------------------- ludob · 2011-12-06 18:56 Quotebut is it only for Windows ?Yes. ---------------------------------------------------------------------- LA.Center · 2011-12-07 22:23 This is what my collegue has done where as fParams is a protected pointer var, and it seem to be working, however the sink has problems with fpc 2.7 Code: [Select]function TActiveX.GetParam(Index: Integer): OleVariant; begin   result := OleVariant(tagDISPPARAMS(fParams^).rgvarg[Index]); end; procedure TActiveX.SetParam(Index: Integer; Value: OleVariant); begin   tagDISPPARAMS(fParams^).rgvarg[Index] := Value; end; procedure TActiveX.Internal_SINK(Sender: TObject; DispID: Integer;        const IID: TGUID; LocaleID: Integer; Flags: Word;        var Params: tagDISPPARAMS; VarResult, ExcepInfo, ArgErr: Pointer); begin   fParams := @Params;   if Assigned(OnXEvent) then   OnXEvent(self, DispID, GUIDToString(IID), LocaleID); end; ---------------------------------------------------------------------- ludob · 2011-12-08 07:42 QuoteCode: [Select]tagDISPPARAMS(fParams^).rgvarg[Index] := Value;Strange. fParams is defined in TActiveX as tagDISPPARAMS and not a pointer to fParams. The other problem is that rgvarg[Index] is a tagVariant record. When you get a value byref the TVarType is VT_BYREF or VT_xxx (VT_xxx being a basic olevariant type: VT_UI4, VT_BOOL, etc) and the value is a pointer to a another tagVariant . When you assign a value to the tagVariant record you will actually overwrite the pointer instead of writing to the location pointed to by the pointer. I'm really surprised that this works (and even compiles). Quotehowever the sink has problems with fpc 2.7What type of problems? I've attached the eventsink code I use with fpc 2.7.1 (svn 18901, that is before the cpnewstr changes). It differs in the TAbstractEventSink declaration, in TAbstractEventSink.Destroy and TEventSink.Destroy.  TAbstractEventSink is now a real refcounted object and freeing itself when refcount=0. ---------------------------------------------------------------------- LA.Center · 2011-12-08 09:14 Isn't rgvarg a TVarData? because otherwise ours would not work, we would need to cast it. for example: Code: [Select]if TVarData(tagDISPPARAMS(fParams^).rgvarg[Index]).vboolean then   TVarData(tagDISPPARAMS(fParams^).rgvarg[Index]).vboolean := Value; is the same as Code: [Select]  tagDISPPARAMS(fParams^).rgvarg[Index] := Value; and also, you have the old TActiveX, put fParams as proteced pointer and have a look at the previous given sink event there the pointer gets assigned before the onXevent is fired. but I myself will investigate this now a bit more. and thanks for the attached eventsink, I will give it a try and see what the diff is. ---------------------------------------------------------------------- LA.Center · 2011-12-08 09:19 ok I found the reason for confusion in my ActiveX unit (the one from lazarus) rgvarg is declared as lpVARIANTARG which is actually a ^variant. but good to know about this, because when we ugrade to a newer version we would have a problem and now thx to you we know already how to solve it. This is proactive coding man