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

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!
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:

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:
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

lnStatus = thisform.oAntView.UnlockStatus

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

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:
<!DOCTYPE html>

<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">


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

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

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.

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

Forum Jump:

Users browsing this thread: 1 Guest(s)