FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour oWebView:Eval() in a loop
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
oWebView:Eval() in a loop
Posted: Thu Feb 16, 2023 02:20 PM
Hi,

In the loop, I call oWebView:Eval() and try to process the results in the Result() function. However, it does not work out in any way :(
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
private oDlg, oWebView

   DEFINE DIALOG oDlg TITLE "This is a dialog" COLOR "N/B" SIZE 400, 200

   @ 3,  8 BUTTON "Test" ACTION Start()

   ACTIVATE DIALOG oDlg ON INIT oDlg:Cargo:={0,0} CENTERED
return nil

function Html()
local cHtml

   TEXT INTO cHtml
      data:text/html,
      <html>
         <head>
            <meta charset="UTF-8" >
         </head>
         <body style="background-color:cyan">
           <button id="bt" style="display:none;">the test is completed</button>
           <script>
              function Test(num) {
                SendToFWH(num) ;
              } ;
              function ViwB() {
                el=document.getElementById("bt").style.display="" ;
              } ;
           </script>
         </body>
      </html>
   ENDTEXT
return cHtml

procedure Start
local st

 if valtype(oWebView)!="O"
   oWebView := TWebView():New()
   oWebView:SetSize(800, 200)
   oWebView:bOnBind = { | cJson, nCalls | Result(cJson) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( Html() )
 endif

 for st=1 to 5
   oWebView:Eval("Test("+ltrim(str(st))+")" )


? oDlg:Cargo[1], oDlg:Cargo[2]
       oDlg:Cargo[1]:=oDlg:Cargo[2]
 next
? oDlg:Cargo[2]
 oWebView:Eval("ViwB()" )
return

function Result(num)
local dat

  Hb_JsonDecode(num, @dat)
  oDlg:Cargo[2]+=dat[1]

? "C", oDlg:Cargo[2]
return
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: oWebView:Eval() in a loop
Posted: Thu Feb 16, 2023 03:44 PM
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: oWebView:Eval() in a loop
Posted: Thu Feb 16, 2023 04:15 PM
Cristobal, thank you for your help, but when trying to download your example, a message appears -
An error when establishing a secure connection
When connected to bbuseruploads.s3.amazonaws.com an error has occurred. The node received a valid certificate, but access was denied.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: oWebView:Eval() in a loop
Posted: Fri Feb 17, 2023 02:03 AM

Dear Natter

What browser are you using?

It is the download server for Fivetech contributions. No one has had any problems. There are already 13 downloads of that file

If when downloading it warns you that the file may be dangerous, ignore the message and download it.

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: oWebView:Eval() in a loop
Posted: Fri Feb 17, 2023 07:41 AM
Cristobal, we didn't understand each other. In my example, I tried to show the problem that I had when working with webview.Eval() in a loop. It is as follows -
1. Webview.Eval() executes a certain JS script and returns the result to the FW.
2. Only after receiving this result can I continue executing the loop. It is this check that I do not succeed. :(
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: oWebView:Eval() in a loop
Posted: Fri Feb 17, 2023 08:52 AM

Dear Yuri,

Your example works fine here too

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: oWebView:Eval() in a loop
Posted: Fri Feb 17, 2023 12:21 PM
In the loop, I call the webview.Eval() method 5 times. Checking the answers looks like this:
1,0 / 2,0 /3,2 / 4,3 / 5,4
Although, as it seems to me, it should be - 1,1 / 2,2 / 3,3 / 4,4 / 5,5
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
private oDlg, oWebView

   DEFINE DIALOG oDlg TITLE "This is a dialog" COLOR "N/B" SIZE 400, 200

   @ 3,  8 BUTTON "Test" ACTION Start()

   ACTIVATE DIALOG oDlg ON INIT oDlg:Cargo:=0 CENTERED
return nil

local cHtml, flg:=.T.

   TEXT INTO cHtml
      data:text/html,
      <html>
         <head>
            <meta charset="UTF-8" >
         </head>
         <body style="background-color:cyan">
           <button id="bt" style="display:none;">Start process</button>
           <script>
              function Test(num) {
                SendToFWH(num) ;
              } ;
              function Viw(num) {
                el=document.getElementById("bt") ;
                el.innerText="total "+num ;
                el.style.display="" ;
              } ;
           </script>
         </body>
      </html>
   ENDTEXT
return cHtml

procedure Start
local st

 if valtype(oWebView)!="O"
   oWebView := TWebView():New()
   oWebView:SetSize(800, 200)
   oWebView:bOnBind = { | cJson, nCalls | Result(cJson) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( Html() )
 endif

 for st=1 to 5
   oWebView:Eval("Test("+ltrim(str(st))+")" )
   millisec(1000)

? st, oDlg:Cargo
 next
 oWebView:Eval("Viw("+ltrim(str(oDlg:Cargo))+")" )
return

function Result(num)
local dat

  Hb_JsonDecode(num, @dat)
  oDlg:Cargo:=dat[1]
return

Continue the discussion