IPythonParameter.Name

Syntax

Name: String;

Name: String;

Description

The Name property determines name of the parameter.

Comments

The name is case-sensitive. If the parameter is sent to the function, which signature does not contain the parameter with the specified name, an exception is thrown.

Example

Executing the example requires a folder with units: d:\Work\Python\. The folder contains the sample.en unit. The unit implements the function that executes various mathematical operations with at least two operands:

def getMathOperationWithOperands(a = 0, b = 0, c = 0):

if (a != 0) and (b != 0) and (c != 0):

return ((a + b) * c)

elif (a != 0) and (b != 0):

return a+b

elif (a != 0) and (c != 0):

return a-c

elif (b != 0) and (c != 0):

return b*c

else:

return -1

Add a link to the Python system assembly.

Sub UserProc;
Var
    pUtils: IPythonUtils;
    pObj1, pObj2, pObj3: IPythonValueObject;
    pParam1, pParam2, pParam3: IPythonParameter;
    Result: Variant;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Create three objects with values
    pObj1 := New PythonValueObject.Create(100);
    pObj2 := 
New PythonValueObject.Create(200);
    pObj3 := 
New PythonValueObject.Create(300);
    
//Create three named parameters
    pParam1 := New PythonParameter.Create("a", pObj1);
    pParam2 := 
New PythonParameter.Create("b", pObj2);
    pParam3 := 
New PythonParameter.Create("c", pObj3);
    
//Execute function with various parameters
    Result := pUtils.Invoke("sample""getMathOperationWithOperands", pParam1, pParam2);
    Debug.WriteLine(Result);
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam2, pParam3);
    Debug.WriteLine(Result);
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam1, pParam3);
    Debug.WriteLine(Result);
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam1, pParam2, pParam3);
    Debug.WriteLine(Result);
    
//Change settings in parameter: a --> b
    Debug.WriteLine("   Change parameter: a --> b");
    pParam1.Name := 
"b";
    pParam1.Value := 
New PythonValueObject.Create(-200);
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam1, pParam3);
    Debug.WriteLine(Result);
End Sub UserProc;

Public Shared Sub Main(Params: StartParams);
Var
    pUtils: IPythonUtils = 
New PythonUtilsClass();
    
pObj1, pObj2, pObj3: PythonValueObject = New PythonValueObjectClass();
    pParam1, pParam2, pParam3: PythonParameter = 
New PythonParameterClass();
    Result: Object;
Begin
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Create three objects with values
    pObj1.Create(100);
    pObj2.Create(
200);
    pObj3.Create(
300);
    
//Create three named parameters
    pParam1.Create("a", pObj1);
    pParam2.Create(
"b", pObj2);
    pParam3.Create(
"c", pObj3);
    
//Execute function with various parameters
    Result := pUtils.Invoke("sample""getMathOperationWithOperands", pParam1, pParam2);
    System.Diagnostics.Debug.WriteLine(Result);
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam2, pParam3);
    System.Diagnostics.Debug.WriteLine(Result);
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam1, pParam3);
    System.Diagnostics.Debug.WriteLine(Result);
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam1, pParam2, pParam3);
    System.Diagnostics.Debug.WriteLine(Result);
    
//Change settings in parameter: a --> b
    System.Diagnostics.Debug.WriteLine("   Change parameters: a --> b");
    pParam1.Name := 
"b";
    pObj1.Create(-
200);
    pParam1.Value := pObj1;
    Result := pUtils.Invoke(
"sample""getMathOperationWithOperands", pParam1, pParam3);
    System.Diagnostics.Debug.WriteLine(Result);
End Sub;

After executing the example three named parameters with values are created. The getMathOperationWithOperands Python function is executed with various combinations of these parameters. Execution results are displayed in the development environment console.

See also:

IPythonParameter