oWebView:Eval() in a loop

Post Reply
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

oWebView:Eval() in a loop

Post by Natter »

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

#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
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: oWebView:Eval() in a loop

Post by cnavarro »

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
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: oWebView:Eval() in a loop

Post by Natter »

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.
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: oWebView:Eval() in a loop

Post by cnavarro »

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
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: oWebView:Eval() in a loop

Post by Natter »

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. :(
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: oWebView:Eval() in a loop

Post by Antonio Linares »

Dear Yuri,

Your example works fine here too
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: oWebView:Eval() in a loop

Post by Natter »

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

#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
Post Reply