Page 1 of 1

moai.CreateObject(FileToString("") fails

Posted: Sun Apr 26, 2020 11:39 am
by plouf
Hi

CreateObject with nested FileTosTring inside fails while works if you load string first

fails with "Error in line 9 (test-rapa.hws): Cannot find MOAI object "115"!" the 115 number is relevand with file size notice tha tchange size of file this number changes too

files are confirmed to be in UTF8 format (also tested with ansi)
do i miss something ?

Windwos7

Code: Select all

@REQUIRE "RapaGUI"


CreateBrush(1,400,400)

moai.CreateApp(FileToString("data\\window.xml"))
test$ = FileToString("data\\prefswin.xml")
moai.CreateObject(test$)	                        ; WORKS
;moai.CreateObject(FileToString("data\\prefswin.xml")) ; FAILS

InstallEventHandler({RapaGUI			 = p_GUIHandle})

moai.DoMethod("basiot", "addwindow", "newwindow")
moai.Set("newwindow", "open", True)

Repeat
	WaitEvent
Forever
prefswin.xml

Code: Select all

<window id="newwindow" title="A new window">
	<vgroup>
			<button>Hello World!</button>
      <button>Hello World!</button>
	 </vgroup>
</window>

Re: moai.CreateObject(FileToString("") fails

Posted: Sun Apr 26, 2020 11:58 am
by jPV
From the documentation you'll notice that FileToString returns two values:
s$, len = FileToString(file$)

So, you're giving the file length as the second argument for moai.CreateObject and it doesn't understand that. It actually expects to get a parent object if the second argument is given:
moai.CreateObject(xml$[, parent$])

Re: moai.CreateObject(FileToString("") fails

Posted: Thu Apr 30, 2020 5:23 am
by SamuraiCrow
A workaround is to make a local string variable to contain the FileToString() output and pass that into the CreateObject() call assuming jPV is correct.