Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Recent enhancements#445

Nov 2, 2023· 1 comments· 2 replies
Discussion options

Recent enhancements to P4D

There have been a large number of enhancements implemented in the Python for Delphi library recently. This discussion provides an overview of these developments.

Python API encapsulation enhancements

Wrapping of Delphi classes and objects

TheWrapDelphi unit allows you to easily wrap your Pascal classes, objects, records and interfaces and expose them to python. It is the technology that makes it possible to expose the whole ofVcl andFmx to python as extension modules. Over the last couple of months, it has been enhanced and expanded in a number of important ways. Here follows a summary of the new features.

  • A new generic class wrapperTPyClassWrapper<T: class> makes it very easy to wrap Delphi classes, without having to create TRegisteredUnit descendants and implementing RegisterWrappers. See below for an example of how to use it.

  • Delphi classes are now exposed as first-class python types. This means that you can use the python functionsisinstance.issubclass,dirwith them and you can call their class methods. Here is an example:

    class TTestclassprocedureDoSomething;classprocedureDoSomethingElse; static;end;// In FormCreate   PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TTest>).Initialize;

    Then in your python code:

    fromdelph_moduleimportTestTest.DoSomething()Test.DoSomethingElse()
  • Class references are also fully supported as function arguments and function results.

  • Class methods and properties are automatically exposed at the class (python type) level. You no longer need to manually expose classes using RegisterMethods, RegisterGetSets etc. Credit to@lmbelo for coming up with the idea and an initial implementation.

  • Published class events are handled automatically. There is no need to create and register TEventHandler subclasses. This includes events that have var parameters. See theunit tests.

  • Functions and procedures with var and out parameters are now fully supported. Here is an example of how to use them:

    class TTestclassprocedureFunc1(var I: Integer): Integer;classprocedureProc(var S: string);end;

    Then in your python code:

    fromdelph_moduleimportTestres,i=Test.Func(i)s=Test.Proc(s)
  • Automatic wrapping of indexed properties including the handling of default properties. See the relatedunit test.

Studying theunit tests for WrapDelphi will help you to better understand how to use the above enhancements, as well as the other features of WrapDelphi.

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

🤞

You must be logged in to vote
2 replies
@maxkleiner
Comment options

Just tested with the 64bit maXbox and Python 3.12 got a
debug: AssertionError: SRE module mismatch 0 err:20
but I think its the missing path environment cause we do have different installs:
python312_Screenshot 2023-11-16 191102

@pyscripter
Comment options

pyscripterNov 17, 2023
Maintainer Author

This is unrelated to P4D and has to do with your python installations. Just google for "SRE module mismatch".

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
3 participants
@pyscripter@kazuser@maxkleiner

[8]ページ先頭

©2009-2025 Movatter.jp