VFP - Cookie Sync example
File(s): extra\cookies.scx
For our cookies demo that uses synchronous methods to manage the cookies for the current html page, we have the following form:

The init method of this form sets up the AntView control and navigates to the URL passed. In this case it is always "https://www.antwise.com/demo/cookies.html".
thisform.init
LPARAMETERS lcurl
thisform.oAntview.Init()
thisform.oAntview.UnlockControl("ExampleCompany","WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F")
lnStatus = thisform.oAntview.UnlockStatus
*-------------------Resize
this.Resize
Thisform.oAntview.navigate(lcurl)
Thisform.refresh
There's a User Defined method called viewstring that displays the data passed as a string in a modal dialog.

thisform.viewstring
*------ Displays a long string in a window
lparameters pcstring
antalias = alias()
create cursor temp (string m)
append blank
replace string with pcstring
DO FORM antlookupv2
use
IF LEN(ALLTRIM(antalias)) > 0
select (antalias)
endif
The button "GetCookies" has the following code in its click event.
cmdGetCookies.click
LOCAL lcCookies, lnreturn
LOCAL loAntViewCookie
LOCAL loAntViewCookieManager
lcCookies = ''
lnReturn = 0
loAntViewCookie = CREATEOBJECT('AntViewAx2.AntViewCookie') && Create the cookie object
loAntViewCookieManager = CREATEOBJECT('AntViewAx2.AntViewCookieManager') && Create the cookiemanager object
loAntviewcookiemanager = thisform.oAntview.object.CookieManager
lnreturn = loAntviewcookiemanager.GetCookiesAsJsonSync(thisform.oAntView.object.Source, @lcCookies)
IF lnreturn > 0
WAIT WINDOW "An error occured. GetCookiesAsJsonSync Cancelled" AT 20,75 timeout 3
ELSE
Thisform.viewstring("Cookies are: "+lcCookies)
lnreturn = loAntviewcookiemanager.GetCookieSync(thisform.oAntview.object.Source,"two",@loAntViewCookie)
IF lnReturn > 0
WAIT WINDOW "An error occured. GetCookieSync Cancelled" AT 20,75 timeout 3
ELSE
Thisform.viewstring("Cookie 'two' value is now: "+loAntviewcookie.value+" and will be changed to 'strawberry'. Next we're adding a new cookie named biscuit.")
loAntViewcookie.value = 'strawberry'
loAntviewcookiemanager.AddOrUpdateCookie(loAntviewcookie)
loAntviewcookie = loAntviewcookiemanager.CreateCookie("extra","biscuit","www.antwise.com","/")
loAntviewcookiemanager.AddOrUpdateCookie(loAntviewcookie)
ENDIF
ENDIF
We first creates the required objects for the Cookie and CookieManager interfaces.
lcCookies = ''
lnReturn = 0
loAntViewCookie = CREATEOBJECT('AntViewAx2.AntViewCookie') && Create the cookie object
loAntViewCookieManager = CREATEOBJECT('AntViewAx2.AntViewCookieManager') && Create the cookiemanager object
loAntviewcookiemanager = thisform.oAntview.object.CookieManager
lnreturn = loAntviewcookiemanager.GetCookiesAsJsonSync(thisform.oAntView.object.Source, @lcCookies)
IF lnreturn > 0
WAIT WINDOW "An error occured. GetCookiesAsJsonSync Cancelled" AT 20,75 timeout 3
ELSE
Thisform.viewstring("Cookies are: "+lcCookies)
The CookieManager dispatch object is then assigned to the loAntViewCookieManager variable. After which we can use it.
The GetCookiesAsJsonSync method returns the cookies as a JSON string in variable lcCookies.
These cookies are then displayed with the viewstring method (see screenshot above).
lnreturn = loAntviewcookiemanager.GetCookieSync(thisform.oAntview.object.Source,"two",@loAntViewCookie)
IF lnReturn > 0
WAIT WINDOW "An error occured. GetCookieSync Cancelled" AT 20,75 timeout 3
ELSE
Thisform.viewstring("Cookie 'two' value is now: "+loAntviewcookie.value+" and will be changed to 'strawberry'. Next we're adding a new cookie named biscuit.")
loAntViewcookie.value = 'strawberry'
loAntviewcookiemanager.AddOrUpdateCookie(loAntviewcookie)
Next up, we get the cookie identified as cookie "two" into variable loAntViewCookie via the GetCookieSync method.
If that was a success, we display the current value with the viewstring method and assign a new value "strawberry" to our cookie.
This is then saved to the html page cookie with the AddOrUpdateCookie method.
Finally we create a new cookie called "extra" via the CreateCookie function and update the page cookie collection.
loAntviewcookie = loAntviewcookiemanager.CreateCookie("extra","biscuit","www.antwise.com","/")
loAntviewcookiemanager.AddOrUpdateCookie(loAntviewcookie)
AntView - The MS Edge WebView2 ActiveX control Date last changed: 11/05/2025