Just starting out? Need help? Post your questions and find answers here.
Quin
Posts: 118 Joined: Wed Nov 08, 2023 4:38 pm
Post
by Quin » Fri Feb 02, 2024 5:58 pm
I'm not sure if this behavior applies to more cases than just this, but you're unable to use OpenXMLDialog() with LoadXML(). It says c.xml is undefined.
Here's the code:
Code: Select all
#Xml = 0
#Dialog = 0
If LoadXML(#Xml, "test.xml") And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "dialog1")
Debug "Dialog successfully created"
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
And here's test.xml:
Code: Select all
<window id='#PB_Any' name='dialog1' text='Dialog example' minwidth='300' minheight='auto' maxheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>
<vbox>
<option name='option1' text='Enter your credit card:' group='1'/>
<string name='string' width='50' height='30'/>
<option name='option2' text='Use paypal account' group='1'/>
<option name='option3' text='Use wiretransfert' group='1'/>
<hbox>
<button name='ok' text='Continue' height='35'/>
<button name='cancel' text='Cancel'/>
</hbox>
</vbox>
</window>
SB 2.51, x86, Windows, using Firefox to render the app.
Peter
Posts: 1197 Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:
Post
by Peter » Sat Feb 03, 2024 12:25 am
SpiderBasic Help wrote:
LoadXML()
[...]
Return value
Nonzero if the xml object has been created. The xml data is still not loaded, the callbacks binded to #PB_Event_Loading and #PB_Event_LoadingError will be called once the loading is done. If #PB_Any was used for the #XML parameter then the generated number is returned on success.
Code: Select all
EnableExplicit
#Xml = 0
#Dialog = 0
Procedure Loading(Type, Filename.s)
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "dialog1")
Debug "Dialog successfully created"
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
EndProcedure
Procedure LoadingError(Type, Filename.s)
Debug Filename + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadXML(#XML, "test.xml")
Quin
Posts: 118 Joined: Wed Nov 08, 2023 4:38 pm
Post
by Quin » Sun Feb 04, 2024 9:50 pm
Nope, that causes the same result here
Code: Select all
Uncaught TypeError: c.xml is undefined
spider_MainXMLNode
http://127.0.0.1:9080/spiderbasic.js?t=1707083223:296
spider_OpenXMLDialog
http://127.0.0.1:9080/spiderbasic.js?t=1707083223:355
f_loading
http://127.0.0.1:9080/spiderbasic.js?t=1707083223:363
SendLoading
http://127.0.0.1:9080/spiderbasic.js?t=1707083223:98
success
http://127.0.0.1:9080/spiderbasic.js?t=1707083223:293
jQuery
4
[Learn More]
spiderbasic.js:296:351
Peter wrote: Sat Feb 03, 2024 12:25 am
SpiderBasic Help wrote:
LoadXML()
[...]
Return value
Nonzero if the xml object has been created. The xml data is still not loaded, the callbacks binded to #PB_Event_Loading and #PB_Event_LoadingError will be called once the loading is done. If #PB_Any was used for the #XML parameter then the generated number is returned on success.
Code: Select all
EnableExplicit
#Xml = 0
#Dialog = 0
Procedure Loading(Type, Filename.s)
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "dialog1")
Debug "Dialog successfully created"
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
EndProcedure
Procedure LoadingError(Type, Filename.s)
Debug Filename + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadXML(#XML, "test.xml")
Fred
Site Admin
Posts: 1820 Joined: Mon Feb 24, 2014 10:51 am
Post
by Fred » Fri May 31, 2024 10:05 am
Works as well here. Be sure to add a check 'If XMLStatus(0) <> #PB_XML_Success' before using the XML because the loading event is different than the fact the XML is properly written:
Code: Select all
EnableExplicit
#Xml = 0
#Dialog = 0
Procedure Loading(Type, Filename.s)
If XMLStatus(0) <> #PB_XML_Success
Debug XMLError(0)
ProcedureReturn
EndIf
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "hello")
Debug "Dialog successfully created"
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
EndProcedure
Procedure LoadingError(Type, Filename.s)
Debug Filename + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadXML(#XML, "ui.xml")
ui.xml:
Code: Select all
<?xml version="1.0"?>
<!-- Window -->
<window id="0" name="hello" text="Window" minwidth="auto" minheight="auto" flags="#PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget">
<hbox expand="item:2">
<vbox expand="no">
<checkbox name="OneInstanceCheckbox" text="Run only one instance ?" disabled="yes" Flags=""/>
<progressbar height="25"/>
<trackbar invisible="no" Flags="#PB_TrackBar_Ticks" height="25"/>
<option text="option 1" name="option1"/>
<option text="option 2"/>
<checkbox name="EnableAlphaBlendingCheckbox" text="Enable alpha-blending" Flags=""/>
<option text="scale x2" name="scale"/>
<option text="scale x3"/>
</vbox>
<editor name="editor" width="200" height="50"/>
</hbox>
</window>