Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AntView equivalent to document.getElementById("info").innerHTML
#1
HI,

Looking for the correct way to do with AntView [VFP sample]:

 m.xString = THISFORM.oleIE.document.getElementById("info").innerHTML

Tried but failed with variants such as:

 m.xString = THISFORM.oleIE.document.RequestElementInnerTextById("info")
 m.xString = THISFORM.oleIE.document.RequestElementInnerHTMLById("info")


Hope someone knows!
Reply
#2
Hello prshope,

You're close, but it needs a few changes.

First a bit of background.
The issue is that a lot of the methods in WebView2 are asynchronous, so when you query for some data, you basically just request the control "Hey, can I have this and that".. The control will then respond to that request via an event. It is natural for a lot of the modern languages and for a web interface where it can take a little while before the request is processed.
For our beloved legacy languages however it is far from natural and it can become a bit painful to do simple things like getting the innerHtml of an element. This is where the old browser control helped us a lot.

So in your code if you issue the RequestElementInnerHtmlById method.. then you have to go and get the result in the OnRequestElementInnerHtmlById event.
That’s not very convenient in VFP (and many other legacy languages) so there’s a synchronous alternative that wraps it up in one method:
RequestElementInnerHtmlByIdSync

Now, how do you use this in VFP?

There's a small example VFP example that comes installed with AntView under C:\users\public\documents\antview\examples\, let's use that to get started quickly.

In the main form change the line of code to start with a different html example file:
Code:
thisform.oAntviewDocument = CREATEOBJECT('AntViewAx.AntViewDocument') && create the AntViewDocument and assign it to a form property
thisform.oAvdCtrl = NEWOBJECT('avdctrl','avdctrl.prg') && CREATEOBJECT("Ctrl") && We need an object for our events
EVENTHANDLER(this.oAntviewDocument,this.oAvdCtrl)

thisform.oAntView.Init()
thisform.oAntView.UnlockControl("ExampleCompany","WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F")
lnStatus = thisform.oAntView.UnlockStatus

thisform.oAntviewDocument.CurrentBrowser = thisform.oAntView.object && this property shows as "Write-only" in the object browser

thisform.text1.Value = [https://antwise.com/demo/SimpleCheckboxExample.html]
thisform.oAntView.object.navigate(ALLTRIM(thisform.text1.Value))

So now the example will start with the SimpleCheckboxExample.html file from the antwise website.
This file is extremely simple and contains the following html:
Code:
<!DOCTYPE html>
<html>
<body>

<h1>Checkbox form example</h1>
<p id="intro">Please make a choice</p>
<form action="#">
  <input type="checkbox" id="bike" name="bike" value="Bike">
  <label for="bike"> I have a bicycle</label><br>
  <input type="checkbox" id="auto" name="auto" value="Car">
  <label for="auto"> I have a car</label><br>
  <input type="checkbox" id="boat" name="boat" value="Boat">
  <label for="boat"> I have a boat</label><br><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>


Then add the following code to a command button:
Code:
LOCAL lcHtml
LOCAL liErr
lcHtml = ''

liErr = thisform.oantviewdocument.RequestElementInnerHtmlByIdSync('intro',@lcHtml)
if liErr = 0
  MESSAGEBOX(lcHtml)
ELSE
  MESSAGEBOX(liErr)
ENDIF

If you press the button it will get the html from the P element and return "Please make a choice" in the message box.

Note hat lcHtml in the method is a variable that needs to be passed by reference.

Hope this helps.
--
Wil
Reply
#3
Wil,

Thank you very much.... The suggested approach works!!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)