Recent

Author Topic: ActiveX  (Read 11152 times)

LA.Center

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
ActiveX
« on: September 09, 2011, 12:48:14 am »
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

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: ActiveX
« Reply #1 on: September 09, 2011, 07:19:27 pm »
Guess no one here uses ActiveX :) -> should have thought so. But any ideas are welcome too.

joseme

  • Full Member
  • ***
  • Posts: 128
    • Logosoft sistemas
Re: ActiveX
« Reply #2 on: December 06, 2011, 05:21:07 am »
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!
un aporte a la comunidad:
http://pascalylazarus.blogspot.com/

joseme

  • Full Member
  • ***
  • Posts: 128
    • Logosoft sistemas
Re: ActiveX
« Reply #3 on: December 06, 2011, 05:26:04 am »
Dont send me the file, finally my browser was able to get it. Thanks!
un aporte a la comunidad:
http://pascalylazarus.blogspot.com/

LA.Center

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: ActiveX
« Reply #4 on: December 06, 2011, 07:46:05 am »
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

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX
« Reply #5 on: December 06, 2011, 08:59:10 am »
Guess 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 ;)
Quote
Does anyone know how to pass ByRef params to a X Object using EventSink?
An EventSink only receives data.

LA.Center

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: ActiveX
« Reply #6 on: December 06, 2011, 09:07:55 am »
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

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX
« Reply #7 on: December 06, 2011, 12:53:38 pm »
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.

OK.
For posterity, the solution is:

Code: [Select]
Params.rgvarg[0].pbool^:=OleVariant(true);

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: ActiveX
« Reply #8 on: December 06, 2011, 06:37:14 pm »
Thanks for sharing, but is it only for Windows ? I don't know a lot about ActiveX, but I guess yes.
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX
« Reply #9 on: December 06, 2011, 07:56:41 pm »
Quote
but is it only for Windows ?
Yes.

LA.Center

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: ActiveX
« Reply #10 on: December 07, 2011, 11:23:35 pm »
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

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX
« Reply #11 on: December 08, 2011, 08:42:54 am »
Quote
Code: [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).
Quote
however the sink has problems with fpc 2.7
What 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

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: ActiveX
« Reply #12 on: December 08, 2011, 10:14:03 am »
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.
« Last Edit: December 08, 2011, 10:15:54 am by plusplus »

LA.Center

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: ActiveX
« Reply #13 on: December 08, 2011, 10:19:54 am »
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 :)
« Last Edit: December 08, 2011, 10:22:03 am by plusplus »

 

TinyPortal © 2005-2018