_Create

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > Data types and variables > TYPE (or UDT User Defined Types) > UDT (User Defined Types) > UDT and Functions > UDT Functions >

_Create

 

_create

 

The optional _create function has following properties:

1.is automatically called once the variable is defined

2.it should never be called explicitly

3.it can take parameters, which can be used for initialization

 

For our case of Point2D it allows us to set x and y during the variable creation.

 

TYPE Point2D
  x AS SINGLE
  y AS SINGLE
  
  FUNCTION _create(x AS SINGLE, y AS SINGLE)
    ME.x = x
    ME.y = y
  END FUNCTION

 
END TYPE
 
DIM point AS Point2D(1, 2)

 

Now x contains 1 and y is equal to 2.

 

As you can see, the _create function is not explicitely called, but any parameters passed to your UDT upon creation are passed to _create automatically.

 

Without _create, you would need to initialize the variable the hard way:

 

DIM point AS Point2D
point.x = 1
point.y = 2