Page 1 of 1

get/set/pro

PostPosted: Thu Nov 06, 2008 10:22 am
by relez
another of my doubts....

this code, using get

Code: Select all
class Punto
   var _xcoor as int
   var _ycoor as int
   var _zcoor as int

   def init(x as int, y as int, z as int)
      _xcoor = x
      _ycoor = y
      _zcoor = z

   get xcoor from var


and this, using pro

Code: Select all
class Punto
   var _xcoor as int
   var _ycoor as int
   var _zcoor as int

   def init(x as int, y as int, z as int)
      _xcoor = x
      _ycoor = y
      _zcoor = z

   pro xcoor from var


are absolutely equivalent or is there some deep difference?

Re: get/set/pro

PostPosted: Thu Nov 06, 2008 5:23 pm
by Charles
"pro" is a read/write property. You can assign to it.

"get" is a read-only property. You cannot assign to it.

class X

# example 1

pro y from var
# is short for the explicit declaration:
pro y as <type of var>
get
return var
set
var = value
# from outside the class you could say:
x = X()
x.y = <expr>
# or within the class:
.y = <expr>

# example 2

get y from var
# is short for the explicit declaration:
pro y as <type of var>
get
return var
# notice the missing "set" part
# you cannot assign to .y