EnglishРусский  

Ads

Installer and installation software
Commercial and Freeware installers.

Type reduction

The as operator

The as operator executes two functions: to assign a value to a variable and to redefine a type. This operator is binary, that has right-to-left associativity. The left-hand operand must be a local variable of uint type. Depending on the value of the right-hand operand, it can be operated in two possible ways:

The first way

The right-hand operand is a structure type name. A value of the local variable is not modified, but its type is redefined with the required one; the variable is assumed to store an object's address, moreover this variable can be treated as the object, ignoring the pointer operation ->.

str  mystr
uint a

a = &mystr
a as str
a = "New value"

The second way

The right-hand operand is an expression that returns an object. An address of the object is assigned to the variable, which redefines its type with the object's type. The object type must be different from numeric types.

str mystr
uint a

a as mystr
a = "New value"

The variable type will be redefined either until the end of the current block or until the next operation as with the variable occurs.

Operator ->

Often you need just to specify that a variable is of a certain structural type. In this case, you can use the -> statement with the name of the required structural type. Together with the type name, you can specify the dimension in square brackets and the type of items with the help of of. The variable -> is applied to can be of not only the uint type, but any structural type.

func myfunc( uint mode, uint obj )
{
   str  ret
   uint val
   
   switch mode
   {
      case 0: myproc( obj->arrstr )
      case 1: print( obj->str )
      case 2: obj->mytest.mytest2str( ret )
      case 3
      {
         val = (obj->arr[,] of ubyte )[1,1]
      }
   }
}

Type сonversion

By default, only integral types byte,ubyte, short, ushort, int, uint are automatically converted into each other, you should use express conversion for other types. For an expression of the type to be converted to another type, it is necessary to specify a type name, to which data will be converted, and the expression enclosed in parentheses; moreover, the conversion will occur if the specified source type has the appropriate method. See more details about such methodson the Method declaration: method page.

str a = "10"
uint b

b = uint( a )

Related links