moai.CreateObject(FileToString("") fails

Discuss GUI programming with the RapaGUI plugin here
Post Reply
plouf
Posts: 470
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

moai.CreateObject(FileToString("") fails

Post 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>
Christos
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

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

Post 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$])
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

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

Post 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.
I'm on registered MorphOS using FlowStudio.
Post Reply