oWebView:Eval() in a loop

oWebView:Eval() in a loop

Postby Natter » Thu Feb 16, 2023 2: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: Select all  Expand view  RUN
#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
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: oWebView:Eval() in a loop

Postby cnavarro » Thu Feb 16, 2023 3:44 pm

For me run Ok
Image
Please try with my executable
https://bitbucket.org/fivetech/fivewin- ... ebView.exe
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
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: oWebView:Eval() in a loop

Postby Natter » Thu Feb 16, 2023 4: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.
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: oWebView:Eval() in a loop

Postby cnavarro » Fri Feb 17, 2023 2: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
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: oWebView:Eval() in a loop

Postby Natter » Fri Feb 17, 2023 7: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. :(
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: oWebView:Eval() in a loop

Postby Antonio Linares » Fri Feb 17, 2023 8:52 am

Dear Yuri,

Your example works fine here too
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: oWebView:Eval() in a loop

Postby Natter » 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: Select all  Expand view  RUN
#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
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 97 guests