IForeNETRuntimeMethodBinding.ByRef

Syntax

ByRef(Index: Integer): Boolean;

Parameters

Index is an argument index.

Description

The ByRef property determines to what arguments in overloaded method should correspond the parameters, passed by the link (parameters with the Var or the Out modifier) in the search.

Comments

Method being executed can contain parameters in its signature, passed by the link, that is, parameters with the Var or the Out modifier. For correct search of such method, determine arguments that correspond to the parameters passed by the link, using this property. To do this, set argument to True in the ByRef property.

By default for all arguments in this property are set to False. Herewith, the search of .NET method, that has the parameters in its signature, passed by value, is performed.

For arguments, passed by the link, the type should be also specified in the Types collection.

The parameters values, passed by the link, can be available in arguments collection after method calculation.

Example

Executing this example requires that the repository contains a .NET assembly with the TestAssm identifier. The TestClass class is implemented in this assembly. There is the TestFunc function in this class, that has two parameters, passed by value and two parameters, passed by link. All parameters have the Integer type.

Sub UserProc;
Var
    MB: IMetabase;
    Run: IForeNETRuntime;
    Asm, Asm1: IForeNETRuntimeAssembly;
    Typ, Typ1: IForeNETRuntimeType;
    Bin: IForeNETRuntimeMethodBinding;
    TypMeth: IForeNETRuntimeMethod;
    Arg: IForeNETRuntimeMethodArgs;
    TypInst: IForeNETRuntimeObjectInstance;
Begin
    MB := MetabaseClass.Active;
    Run := ForeNETAssemblyClass.Runtime;
    //User assembly and type
    Asm := Run.Assembly(MB.ItemById("TestAssm").Bind As IForeNETAssembly);
    Typ := Asm.Type("TestAssm.TestClass");
    //Assembly mscorlib for receiving parameters of type
    Asm1 := Run.SystemAssembly("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac");
    Typ1 := Asm1.Type("System.Int32");
    //Instance type
    TypInst := Typ.CreateInstance;
    //Connection for searching overloaded method
    Bin := Run.CreateBinding(4);
    Bin.Types.Item(0) := Typ1;
    Bin.Types.Item(1) := Typ1;
    Bin.Types.Item(2) := Typ1;
    Bin.Types.Item(3) := Typ1;
    //Indication of arguments, corresponding to parameters by link
    Bin.ByRef(2) := True;
    Bin.ByRef(3) := True;
    //Receiving method
    TypMeth := Typ.Method("TestFunc", Bin);
    //Creating arguments for execution of method
    Arg := Run.CreateArgs(4);
    //Setting the values
    Arg.Value(0) := 1;
    Arg.Value(1) := 2;
    //Executing the method
    TypMeth.Invoke(TypInst, Arg);
    //Receiving values of parameters, that are passed by link,
    //and that were calculated at execution of method
    Debug.WriteLine(Arg.Value(2));
    Debug.WriteLine(Arg.Value(3));
End Sub UserProc;

On executing the example the context of the TestAssm assembly is received. The TestClass type is received and the object instance of this type is created from this assembly. To search the overloaded method the connection is created and types of arguments are specified. On executing the TestFunc method, the output values are put into the parameters passed by the link. These values are available in the Arg collection of arguments.

See also:

IForeNETRuntimeMethodBinding