GetAttr(AttrName: String): Variant;
AttrName. Class argument name. The name is case-sensitive.
The GetAttr method gets values of the argument with the specified name from class instance.
If the class instance does not contain an argument named AttrName, an exception is thrown.
Executing the example requires a folder with modules: d:\Work\Python\. The folder contains the sample.py module. The following class is implemented in the module:
class Door:
def __init__(self, color, height, width):
self.color = color
self.height = height
self.width = width
def getDoorDescription(self, comment):
return comment + ". Color: " + self.color + " Size: " + str(self.height) + "X" + str(self.width) + " mm"
Add a link to the Python system assembly.
Sub UserProc;
Var
pUtils: IPythonUtils;
pObj: IPythonClassObject;
Result: Variant;
Begin
pUtils := New PythonUtils.Create;
pUtils.AddFolderToPythonPath("d:\Work\Python\");
//Create object of the Door class
pObj := New PythonClassObject.Create("sample", "Door", "Red", 2000, 800);
//Get value of the color attribute
Result := pObj.GetAttr("color");
Debug.WriteLine(Result);
//Change value of the color attribute
pObj.SetAttr("color", "White");
//Execute function of the class instance
Result := pObj.Invoke("getDoorDescription", "Connecting door");
Debug.WriteLine(Result);
End Sub UserProc;
The following operations are executed on starting the example:
An instance of the Door class is created. The constructor sends values of parameters that will be assigned to attributes.
Value of the "color" attribute is obtained for the created object. The value is displayed in the development environment console.
The new value is set for the "color" attribute.
The function of the getDoorDescription class instance is executed, the obtained result is displayed in the development environment console.
See also: