CreateArgs(ArgCount: Integer): IForeNETRuntimeMethodArgs;
ArgCount. Number of arguments.
The CreateArgs method creates the collection of arguments that are further used to execute some method.
The collection of arguments contains the specified values that are necessary at the execution of some .NET methods. This collection can be used in the following methods:
To each argument it is necessary to create the setting that binds the value of argument with its type. It is necessary for correct execution of different overloaded methods. The binding of arguments with correspondent types is performed in the IForeNETRuntimeMethodBinding.Types collection. Each argument should be bound with type that is determined in signature of .NET method. If the .NET method being executed contains in its signature the parameters, that are passed by link, these parameters should be also taken into account in the collection, that is created by this method. These arguments contain the values, received as the result of .NET method execution.
To create a bind with types of arguments, the CreateBinding method is used.
Consider an example of creation of the object instance of the System.Drawing.Font type. This type is implemented in the System.Drawing assembly and implements different fonts. There is the constructor for the type: Font(FontFamily, Single, FontStyle) for this type, where FontFamily is font name, Single is font size, FontStyle is font style.
Sub UserProc;
Var
Run: IForeNETRuntime;
Asm, Asm1: IForeNETRuntimeAssembly;
Arg: IForeNETRuntimeMethodArgs;
Bind: IForeNETRuntimeMethodBinding;
Typ, Typ1, Typ2, Typ3: IForeNETRuntimeType;
TypInst: IForeNETRuntimeObjectInstance;
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");
Typ := Asm.Type("System.Drawing.Font");
//Types of parameters, used in designers
Typ1 := Asm1.Type("System.String");
Typ2 := Asm1.Type("System.Single");
Typ3 := Asm.Type("System.Drawing.FontStyle");
//Values of parameters, necessary for constructor
Arg := Run.CreateArgs(3);
Arg.Value(0) := "Arial";
Arg.Value(1) := 14;
//Value 5 corresponds to combination of .NET type: (FontStyle.Bold Or FontStyle.Italic)
Arg.Value(2) := 5;
//Creation of binding for determination of search parameters of overloaded method
Bind := Run.CreateBinding(3);
Bind.Types.Item(0) := Typ1;
Bind.Types.Item(1) := Typ2;
Bind.Types.Item(2) := Typ3;
//Creation of instance of font with given parameters
TypInst := Typ.CreateInstance(Arg, Bind);
End Sub UserProc;
On executing the example the context of the System.Drawing assembly is received. The System.Drawing.Font type, that is used to create of different fonts, is received from this assembly. Three arguments are created to use the constructor. To search corresponding overloaded constructor the binding is created. The types of designer parameters are indicated in the settings of this binding. After this the font instance with indicated parameters is created. This font can be further used to determine fonts of different .NET components, or in cases that require the arguments with System.Drawing.Font type.
See also: