Click or drag to resize

_CreateInstance Function (String, Usual)

X#
Create an object.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION _CreateInstance(
	symClassName AS STRING,
	InitArgList AS USUAL[]
) AS Object
Request Example View Source

Parameters

symClassName
Type: String
The name of the class for which you want to create an object.
InitArgList
Type: Usual
A comma-separated list of arguments to pass to the Init() method of symClassName (see example below).

Return Value

Type: Object
Remarks
CreateInstance() is the functional way to create an object of a particular class.
It is essentially the same as creating an object through an invocation of {}, but is useful in situations where a functional form is needed.
Examples
This example shows how an object is created using CreateInstance():
X#
 1CLASS Person
 2    EXPORT name, sign
 3CONSTRUCTOR(tName, tSign)
 4    name := tName
 5    sign := tSign
 6END CLASS
 7
 8FUNCTION Start()
 9    LOCAL x AS OBJECT
10    // Pass the class name as symbol and also
11    // specify all Init() method arguments.
12    x :=  CreateInstance(#PERSON, "Odile", "H")
13    ? x:name                            // Odile
See Also