iqrf 3 Posted June 6, 2023 Hi, Let's take Demo08 as an example where a myPoint object is created in Delphi. I need to detect on the Delphi side if the assignment spam.myPoint = None is made in Python. Cyclic polling using PythonModule1.GetVar('myPoint') is inappropriate for me. I would need something like OnChange in TPythonDelphiVar. I've studied PythonEngine.pas and can't think of anything. Thank you for your opinion. Share this post Link to post
pyscripter 694 Posted June 6, 2023 (edited) function TPyPoint.SetAttr(key : PAnsiChar; value : PPyObject) : Integer is called whenever a property is set (e.g. spam.myPoint.x = 10). So you can take an action when the object is modified. However you are not notified when spam.myPoint is assigned a value. To do what you would have to override the __setattr__ on the module, but this is too complicated. Edited June 6, 2023 by pyscripter Share this post Link to post
iqrf 3 Posted June 7, 2023 Couldn't this be done at the Python level using a decorator above the module? import types class MyModule(types.ModuleType): def __setattr__(self, name, value): print(f"Setting attribute {name} to value {value}") super().__setattr__(name, value) mymodule = MyModule('mymodule') mymodule.my_attribute = 42 print(mymodule.my_attribute) Share this post Link to post
pyscripter 694 Posted June 7, 2023 Not so simple: python - Overriding __setattr__ at runtime - Stack Overflow 1 Share this post Link to post
iqrf 3 Posted June 7, 2023 It's really not easy, so I'll accept the imperfection and try to solve it sometime in the future. Thanks Share this post Link to post