Need Help Understanding CreateObject()

Hi All,

I’m working through the demo projects in the SDK and was hoping someone could shed more light on the CreateObject() method? In the Reference Manual it simply says it “creates a BrightScript Component of class name specified”, which doesn’t really tell me much as it seems integral to BrightScript as it’s used often.

Is there somewhere else that describes the proper use of CreateObject() somewhere? Specifically, the String that you give it, what is that? Is it random ad-hoc based on developers design time naming or do you have to follow a certain set standard of values? For example, if I create foo = CreateObject(“roWhateverIWant”), will this do anything?

Also, it seems you can pass it optional parameters, where are these defined and what do they do??

Basically, is there a better description on how to use CreateObject() than what’s outlined in the Reference Manual?

Thanks!!
Bud

The components you can create are detailed in the “Core Brightscript Components” section of the BrightScript reference, and in the ComponentReference.pdf. Any optional parameters are defined in the specific component documentation. You cannot create your own components, so only intrinsic BrightScript component names are valid for CreateObject().

Create object is like the DIM statement in other languages - to create an array you would do something like

variablename=CreateObject("roarray",1,true) 

to create an array with one dimension that can grow in size.
to create a posterscreen, you would set a variable like

p=createobject("roposterscreen") 

after which point p is a posterscreen and you can do anything with it, like show it:

p.show() 

close it

p.close()

, set the text

 p.setbreadcrumbtext("Hello","World")

There are other ways to create these variables, like

variablename=[] 

will also create an roarray

and

x=1 

will create x as an integer with a value of one, you can also do

 x=createobject("roint")
  • Joel

“jbrave” wrote:
Create object is like the DIM statement in other languages
Not exactly. BrightScript actually has it’s own DIM statement (just like VB/VBScript). CreateObject() is the way to create the object that you’re going to assign to a DIM’d variable. In fact, it’s pretty much identical to the VBScript function of the same name: http://msdn.microsoft.com/en-us/library … 85%29.aspx

Great info and references, thanks all!!