Contents - Index - Top


PowerBuilder - Fill form example

 

This example shows how-to use the document interface with PowerBuilder.

As it is very difficult in PowerBuilder to use events for an automation interface, we have added synchronized wrapper methods to the asynchronous methods.

 

In event open we configure our web control (edgewebbrowser) and create the document object instance.

 

event open;

// Create the webview2 control

edgewebbrowser.object.CreateWebView()

 

int i

 

io_Document = CREATE OLEObject

i = io_Document.ConnectToNewObject("AntViewAx.AntViewDocument") // i should be 0

// connect the document interface to the current browser object

io_Document.BrowserDispatch(edgewebbrowser.object.IDispatchPointer)

 

// example on how you can unlock the control once you acquired a license.

edgewebbrowser.Object.UnlockControl("ExampleCompany", "WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F")

end event

 

It is required to connect the document object with the browser object. This can be done with the BrowserDispatch method like above.

 

 

First press the "Go" button in the view to open the web page.

The relevant part in the html looks like this:

    <form id="login" class="login" action="thankYou.html">

        <div class="loginName">

            <label for="username">UserName</label>

            <input type="text" name="username" placeholder="User Name" required />

        </div>

 

        <div class="loginPassword">

            <label for="password">Password</label>

            <input type="password" name="password" placeholder="Password" required />

        </div>

 

        <div class="loginBtn">

            <button id="submit" type="submit" name="submit">Login</button>

        </div>

    </form>

 

Then via the "Fill Form" button you can add data to the html inputs in the screen.

 

The click event in the "Fill Form" button has this code:

string is_formValue

integer ii_error

 

is_formName = "username" 

is_formValue = "Mr.Smith"

ii_error = io_Document.SetElementValueByNameSync(is_formName,is_formValue)

if ii_error <> 0 then

  MessageBox("setting username", "The returned error =  " + string(ii_error))

end if 

 

is_formName = "password" 

is_formValue = "supersecret"

ii_error = io_Document.SetElementValueByNameSync(is_formName,is_formValue)

if ii_error <> 0 then

  MessageBox("setting password", "The returned error =  " + string(ii_error))

end if 

 

The function SetElementValueByNameSync takes both the form name as well as the value as parameters and will return 0 if it was able to execute that function.

 

You can also read the contents of any of the html inputs in a similar way.

 

See the click event of the "Read Form" button for this:

event clicked;string is_formName

string is_username

string is_password

integer ii_error

 

is_formName = "username" 

is_username = ""

ii_error = io_Document.requestelementvaluebynamesync(is_formName,REF is_username)

if ii_error <> 0 then

  MessageBox("username", "The returned error =  " + string(ii_error))

end if 

 

is_formName = "password" 

is_password = ""

ii_error = io_Document.requestelementvaluebynamesync(is_formName,REF is_password)

if ii_error <> 0 then

  MessageBox("password", "The returned error =  " + string(ii_error))

end if 

 

MessageBox("Result", "username =  " + is_username + "~r~npassword = " + is_password)

 

end event

 

Here we use the RequestElementValueByNameSync function and the result of that function is immediately passed back in the Value parameter. For example in "is_username". 

That parameter is passed by reference via the "REF" keyword.

 


AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/25/2024