Jump to content
AlexanderMi

convert native object instance to wrapped instance

Recommended Posts

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.

Share this post


Link to post
Posted (edited)

See 

TPyDelphiWrapper.Wrap(AObj: TObject;  AOwnership: TObjectOwnership): PPyObject;

 

Also you do need need your TPyEventFromScript.  This is the old and hard way.  You can use instead (e.g. in your FormCreate):

 

PyDelphiWrapper1.RegisterDelphiWrapper(TPyClassWrapper<TEventFromScript>).Initialize;

 

 

Since you are using interfaces there is also:

function TPyDelphiWrapper.WrapInterface(const IValue: TValue): PPyObject;

 

Edited by pyscripter

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×