How to use the keyword 'Object' ?

BlitzMax Forums/BlitzMax Beginners Area/How to use the keyword 'Object' ?

semar(Posted 2005) [#1]
All,
my goal is to build a function type - or a method - which accepts any type structure, like for example:

type base
function create(t:type)
local test:t = new t
return test
end type
The above code does not compile: seems that 'Type' can't be defined as parameter.

So I tryed with 'Object':
type base
function create(t:Object)
local test:t = new t
end type
But no luck.

The goal here, is to make something like:
type base
function create(o:whatever)
local test:o = new o
end function
end type

type A extends base
end type

type B extends base
end type

.
.
base.create(A)
base.create(B)
Am I missing something obvious here ?

So far, the way to make what I mean, seems to be this:
type base

function create(o:base)
.
.
end function

type A extends base
end type

type B extends base
end type

.
.
base.create(New A)
base.create(New B)
This works, but I wanted to create the base class in such a manner that I can make that 'New A' or 'New B' in the function body - that is, inside the base type function, instead of in the function call.

In other terms, the base type should be able to create a new type instance, without to know which type is passed to it.

I hope I explained the question; another example could be the Object implementation in VB.NET:

function set_text(control as Object)
control.text = "hello"
end function

you can then call the above function with any 'object' - all of them should have, of course, a property called 'text' in order to work.

In the following example, the function is called with two different object types, a label and a textbox:

dim lab as new label
dim tex as new textbox
set_text(lab)
set_text(tex)


Thanks in advance,
Sergio.


Dreamora(Posted 2005) [#2]
you can't do it this way

You can not use objects to create new objects, new is meant for Typenames like base. there is no "new like object" command