Invoke(
Instance: IForeNETRuntimeObjectInstance;
[Args: IForeNETRuntimeMethodArgs = Null]): IForeNETRuntimeObjectInstance;
Instance. The object instance for which .NET method is executed. If the static method of any class is executed, Null must be sent as a value.
Args. Array of arguments, that are used as values of executed method parameters.
The Invoke method executes the given .NET method for the specified instance of object.
Sub UserProc;
Var
Run: IForeNETRuntime;
Asm, Asm1: IForeNETRuntimeAssembly;
Typ, Typ1: IForeNETRuntimeType;
Bin: IForeNETRuntimeMethodBinding;
TypMeth: IForeNETRuntimeMethod;
Arg: IForeNETRuntimeMethodArgs;
TypInst: IForeNETRuntimeObjectInstance;
v: Array;
Begin
Run := ForeNETAssemblyClass.Runtime;
Asm := Run.SystemAssembly("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
Asm1 := Run.SystemAssembly("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac");
//Type, instance of which needs to be created
Typ := Asm.Type("System.Drawing.Color");
//Type of parameter, used in method for instance creation
Typ1 := Asm1.Type("System.String");
//Connection to search overloaded method
Bin := Run.CreateBinding(1);
Bin.Types.Item(0) := Typ1;
//Flags used at search
Bin.Flags := MethodBindingFlags.Static Or MethodBindingFlags.Public_;
//Get static method named FromName
TypMeth := Typ.Method("FromName", Bin);
//Create an argument for method execution
Arg := TypMeth.CreateArgs;
Arg.Value(0) := "Purple";
//Executing the method
//Result of method execution is color instance
TypInst := TypMeth.Invoke(Null, Arg);
v := New Variant[0];
//Get color parameters
Debug.WriteLine(TypInst.InvokeMethod("get_R", v));
Debug.WriteLine(TypInst.InvokeMethod("get_G", v));
Debug.WriteLine(TypInst.InvokeMethod("get_B", v));
End Sub UserProc;
On executing the example the context of the System.Drawing assembly is received. The type System. Drawing. Color used to create of various colors is received from this assembly. The FromName static method is used to create instance of this type. Before receiving a context of this method, the binding, that determines parameter type and flags used for overloaded method search, is created. After the method is received, it is executed with specified value of argument. Number methods, that return three components of color, are executed for received object instance. The results are displayed in the development environment console.
See also: