Difference between revisions of "ConstructorInfo.Invoke"

From Xojo Documentation

 
Line 15: Line 15:
 
This code gets the '''ConstructorInfo''' for the [[FolderItem]] class. The Invoke method is used to create a new instance based on the constructor that takes no parameters.
 
This code gets the '''ConstructorInfo''' for the [[FolderItem]] class. The Invoke method is used to create a new instance based on the constructor that takes no parameters.
 
<rbcode>
 
<rbcode>
Dim ti As Introspection.TypeInfo = GetTypeInfo(FolderItem)
+
Var ti As Introspection.TypeInfo = GetTypeInfo(FolderItem)
Dim ci() As Introspection.ConstructorInfo = ti.GetConstructors
+
Var ci() As Introspection.ConstructorInfo = ti.GetConstructors
  
Dim f As FolderItem
+
Var f As FolderItem
 
f = ci(0).Invoke
 
f = ci(0).Invoke
 
</rbcode>
 
</rbcode>

Latest revision as of 21:54, 16 July 2019

Method

ConstructorInfo.Invoke([params() as Variant]) As Datatype of the object being instantiated.

Supported for all project types and targets.

Invokes the constructor. Pass the optional array of variants for the constructor's parameter values, if any. You will get an OutOfBoundsException if the number of parameters does not match or an IllegalCastException if the types do not match.

Sample Code

This code gets the ConstructorInfo for the FolderItem class. The Invoke method is used to create a new instance based on the constructor that takes no parameters.

Var ti As Introspection.TypeInfo = GetTypeInfo(FolderItem)
Var ci() As Introspection.ConstructorInfo = ti.GetConstructors

Var f As FolderItem
f = ci(0).Invoke