Forum Discussion

Eppo's avatar
Eppo
New Contributor
10 years ago
Solved

Call a c# function from testcomplete with a int[] parameter

I'm trying to call a c# library function from within my testcomplete script (using delphiscript). The c# function is structured as follows: (built target .net 4.0) public object CSharpFunction(int[]...
  • HKosova's avatar
    10 years ago

    I see you already got an answer on Stack Overflow, but I'll recap it here just in case - you need to create .NET arrays and enums explicitly by using the dotNET object:

     

    function CallManagedFunction(
       CSharpLibrary: OleVariant;
       singleId: integer; 
       enumParameter: integer);
    var functionResult, arrType, arrayOfIntegers, enumType, enumValue;
    begin
      // Create a .NET array with 1 element
      arrType := dotNET.System.Type.GetType('System.Int32');
      arrayOfIntegers := dotNET.System.Array.CreateInstance(arrType, 1);
      arrayOfIntegers.SetValue(singleId, 0);
    
      // Convert a number to an enumeration member
    // TODO: replace 'System.DayOfWeek' with your enum type
    enumType := dotNET.System.Type.GetType('System.DayOfWeek'); enumValue := dotNET.System.Enum.ToObject_3(enumType, enumParameter); functionResult := CSharpLibrary.CSharpFunction(arrayOfIntegers, enumValue); // Parse result object end;