[Gambas-user] Calling a sub from a Webview

Jesus ea7dfh at ...2382...
Wed Dec 4 23:48:13 CET 2013


El 04/12/13 23:33, Tobias Boege escribió:
> On Wed, 04 Dec 2013, Jesus wrote:
>> El 04/12/13 22:32, Tobias Boege escribi?:
>>> On Wed, 04 Dec 2013, Jesus wrote:
>>>> Hi all
>>>>
>>>> I currently helping to port a VB6 program to Gambas3, but to my
>>>> surprise, it does weird things like these from the post title: it is
>>>> calling methods and functions from the html code inside a webbrowser
>>>> control.
>>>>
>>>> It has a wb control that acts like a sort of wizard/help thing, and the
>>>> html links in that view are calling methods inside the application. That
>>>> links are as '<a href="act:some_class.method">some action</a>'
>>>>
>>>> So the question is, could it be done with gambas somehow?
>>>>
>>>> Regards
>>>> --
>>>> Jesus Guardon
>>>
>>> Jesus (meant as an interjection)! I know I shouldn't question other people's
>>> design choices but this is just mad. Actually it might have seemed like an
>>> elegant way to communicate with an HTML page to the original author of that
>>> program - I understand that - but this is just asking for trouble, IMHO.
>>>
>>> However, I guess Object.Call() is your best bet here.
>>>
>>> Regards,
>>> Tobi
>>>
>>
>> Hi Tobi, thanks for reply
>>
>> I am at your side about some (mad) practices, but...
>>
>> I think Object.Call is suitable for calling or executing code inside or
>> outside of the current class, but not the other way round, IIUC. How
>> could I execute Object.Call from inside a webview? None of the events
>> webview exposes are suitable for doing this IMO, since the webview.url
>> is a property, not a method.
>>
>> I will experiment, thanks for the tip!
>>
>
> Ahh, I got you wrong apparently... My answer can be applied if you have any
> occasion (event) to parse an (X)HTML element for this special attribute
> href="act:some_class.method". Then you can extract the class and method name
> and use Object.Call().
>
> You can (ab)use the WebView's Click event like this: Modify the <a> element
> to look like this:
>
> <a href="#act:some_class.method">some action</a>
>
> Then, when clicked, the WebView will load the valid URL (the anchor sign had
> to be prepended to make it valid - to trigger the Click event, in turn) and
> provide you a WebFrame object in whose Url property you have the wanted
> act:some_class.method string somewhere. Now parse and execute.
>
> I think it's too late for me to find clear words, so I attach a minimal
> example. (Note that the code is executed twice in this project which is
> certainly not desirable. You'll sure find a way to prevent this yourself.)
>
> Regards,
> Tobi

Many thanks, Tobi

I think this is a good starting point. Just hope I will not get crazy 
after that. Now I'm going to sleep and tomorrow I will give it a fresh 
(re)view.

Regards
-- 
Jesus Guardon




More information about the User mailing list