Olaf Doschke
Programmer
I am currently working on an API involving the necessity to go through JS functions I load into a Webbrowser control, as the endpoint API is using things like postMessage JS, which need a JS eventlistener.
I can get back a JS parameter "event" and Intellisnse shows me properties and subobjects and their properties, but I get error "Unknown Name" when I access properties with uppercase letters and properties of second or deeper levels no matter how the names are composed.
I found one solution in using a JS function "flattenobject" from and modified this to use '_' instead of '.' and create lower case names only. That still risks one problematic case where the JS object has a property oobject.test.property and object.test_property causing a conflict when test.property is added as the already existing test_property.
Besides solving that with a more complex replacement I remember there should be an easy solution, as JS objects also can be accessed with bracket notation in JS: object.['test.property'], but doing so with the object arriving in Foxpro isn't working anymore. I've seen a case where this was about native names invalid for VFP naming conventions, but I don't find that, it would be easier than fiddling with any reworking of JS objects before returning them to VFP.
EDIT: To illustrate the problem some reprocode:
To clarify: In this case, I could prevent the errors by simply defining all property names in lower case, but in the real world scenario the names of the JS properties are not in my control, they are partially native JS properties and partially added from the Restful API I use.
Also note: The 'sosoworkingproperty' can be read and is printed without error, but if you set a breakpoint in the oInbox_assign method and use intellisense to address the properties, you get obj listed when you type [tt][highlight #FFFFFF]vNewVal.[/highlight][/tt], but then [tt][highlight #FFFFFF]vNewVal.obj.[/highlight][/tt] is not telling you, that the sosoworkingproperty exists.
Bye, Olaf.
Olaf Doschke Software Engineering
I can get back a JS parameter "event" and Intellisnse shows me properties and subobjects and their properties, but I get error "Unknown Name" when I access properties with uppercase letters and properties of second or deeper levels no matter how the names are composed.
I found one solution in using a JS function "flattenobject" from and modified this to use '_' instead of '.' and create lower case names only. That still risks one problematic case where the JS object has a property oobject.test.property and object.test_property causing a conflict when test.property is added as the already existing test_property.
Besides solving that with a more complex replacement I remember there should be an easy solution, as JS objects also can be accessed with bracket notation in JS: object.['test.property'], but doing so with the object arriving in Foxpro isn't working anymore. I've seen a case where this was about native names invalid for VFP naming conventions, but I don't find that, it would be easier than fiddling with any reworking of JS objects before returning them to VFP.
EDIT: To illustrate the problem some reprocode:
Code:
Local loJSForm, lcScript, loDocument, loScript, loText, lcJSON
loJSForm = CreateObject('jsform')
Text To lcScript NoShow
function json2vfp(json, vfpreceiver) {
vfpreceiver.oInbox = JSON.parse(json)
}
EndText
loDocument = loJSForm.oWeb.Document
loScript = loDocument.createElement('script')
loScript.setAttribute('type', 'text/javascript')
loText = loDocument.createTextNode(lcScript)
loScript.appendChild(loText)
loDocument.documentElement.appendChild(loScript)
Text To lcJSON NoShow
{ "workingproperty": true,
"nonWorkingProperty": false,
"obj": { "notatallWorkingProperty" : false,
"sosoworkingproperty": true
}
}
EndText
Clear
On Error ?? Line(), Message()
loDocument.Script.json2vfp(lcJSON, loJSForm)
Define Class jsform As Form
Add Object oWeb As cWeb
oInbox = .Null.
Procedure oInbox_assign(vNewVal)
This.oInbox = vNewVal
? 'workingproperty', vNewVal.workingproperty
? 'nonWorkingProperty', vNewVal.nonWorkingProperty
? 'obj.notatallWorkingProperty', vNewVal.obj.notatallWorkingProperty
? 'obj.sosoworkingproperty', vNewVal.obj.sosoworkingproperty
Endproc
Enddefine
Define Class cWeb As OleControl
OleClass="Shell.Explorer.2"
Procedure Init()
This.navigate2("about:blank")
Do While This.oWeb.readyState<>4
DoEvents Force
Enddo
Endproc
Procedure Refresh()
Nodefault
Endproc
Enddefine
To clarify: In this case, I could prevent the errors by simply defining all property names in lower case, but in the real world scenario the names of the JS properties are not in my control, they are partially native JS properties and partially added from the Restful API I use.
Also note: The 'sosoworkingproperty' can be read and is printed without error, but if you set a breakpoint in the oInbox_assign method and use intellisense to address the properties, you get obj listed when you type [tt][highlight #FFFFFF]vNewVal.[/highlight][/tt], but then [tt][highlight #FFFFFF]vNewVal.obj.[/highlight][/tt] is not telling you, that the sosoworkingproperty exists.
Bye, Olaf.
Olaf Doschke Software Engineering