Jump to content

AlexanderMi

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. I have delphi object and wrapped class to use in python. TEventFromScript = class(TInterfacedObject, IEventFromScript) strict private FData: string; function GetData: string; procedure SetData(const AValue: string); public property Data: string read GetData write SetData; end; TPyEventFromScript = class(TPyDelphiObject) private // Getter function Get_Data(AContext: Pointer): PPyObject; cdecl; // Setter function Set_Data(AValue: PPyObject; AContext: Pointer): Integer; cdecl; function GetDelphiObject: TEventFromScript; procedure SetDelphiObject(const Value: TEventFromScript); public constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override; class function DelphiObjectClass: TClass; override; class procedure RegisterGetSets(PythonType: TPythonType); override; // Properties property DelphiObject: TEventFromScript read GetDelphiObject write SetDelphiObject; end; I can use in python wrapped TPyEventFromScript and it is ok. I can use TventFromScript in delphi. But... at some point I need pass TEventFromScript instance to python. How I can somwhow convert it to TPyEventFromScript? e.g. on delphiI have TQueue<TEventFromScript > and on python side I have a function who returns dequeued TEventFromScript, I need tell to python that it now responsible for returned object... convert TEventFromScript to TPyEventFromScript and forget.
  2. AlexanderMi

    python4delphi How to stop inifinity script

    from delphi side provide a py module and in run-time create an instance of class which holds "Terminated" property (and you able to get/set), and set it as variable for module. Then in python you can run infinite loop so long as needed: from DelphiModule import RuntimeVar from time import sleep from pyio import write as print def run(): while not RuntimeVar.Terminated: print('Wauting for something') sleep(1) #1 second sleep else: print('infinite loop ended by delphi side') run() until host app not set Terminated to true yet. Due to that design, your python code should run in thread.
×