Git Product home page Git Product logo

Comments (11)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
Issue 18 has been merged into this issue.

Original comment by pyscripter on 2 Nov 2011 at 1:45

from python4delphi.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
Have you looked into WrapDelphi and the relevant demos?  This is exactly what 
WrapDelphi does, although it does not use the improvements in RTTI since Delphi 
2009.  However it does make it very easy to expose Delphi objects to Python.

Original comment by pyscripter on 8 Nov 2011 at 9:27

from python4delphi.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
Thanks for the hint! It's much easier then Demo08.

Original comment by [email protected] on 10 Nov 2011 at 1:21

from python4delphi.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
I've changed wrapdelphi.pas to use TRttiContext when delphi version is 
DELPHIXE_OR_HIGHER. How I can contribute with this project?

Original comment by [email protected] on 28 Jan 2012 at 4:52

Attachments:

from python4delphi.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
Thanks, I will review the changes and merge them.

Original comment by pyscripter on 28 Jan 2012 at 4:43

from python4delphi.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
Now, python code like "Form1.Memo1.Lines.Add('New line')" is working!
But "print Form1.Memo1.Text" is not working.
Please add 'tkUString' to line 1551.

Original comment by [email protected] on 4 Feb 2012 at 10:12

from python4delphi.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
Sounds great!

Original comment by [email protected] on 5 Mar 2012 at 9:00

from python4delphi.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 24, 2024
@ pyscripter, 

Have you merged WrapDelphi.pas by Alexandre into the python4delphi project 
already? Thanks!

Original comment by [email protected] on 26 May 2012 at 8:53

from python4delphi.

pyscripter avatar pyscripter commented on May 24, 2024

Sorry about the delay in getting back to you on this. I have tried merging the new RTTI staff, but after some effort, I still cannot get demo 31 to work without errors. The attached file contains the modified WrapDelphi.pas. If anyone can bring this to a state where all the tests of demo 31 pass, I will happily merge it.

WrapDelphi.zip

from python4delphi.

liuzg2 avatar liuzg2 commented on May 24, 2024

i download the wrapdelphi.pas
found some error
1、

procedure TPyDelphiWrapper.CreatePyFunc(AModule: TPythonModule; AMethodDef: PPyMethodDef);
var
d : PPyObject;
begin
if Assigned(FModule) and FModule.Initialized then
with GetPythonEngine do
begin
d := PyModule_GetDict(FModule.Module);
Assert(Assigned(d));
if IsPython3000 then
PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_NewEx(AMethodDef, nil, nil))
else
PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_New(AMethodDef, nil));
end;
end;
2 、when triiger draw ,report accesse error .
def grdTestDrawCell(self, Sender, Col, Row, Rect, State):

   Sender.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, "%d " % (Col))

from python4delphi.

pyscripter avatar pyscripter commented on May 24, 2024

Implemented:

  • Major refactoring and clean-up
  • In Delhi version newer than XE, enhanced RTTI is used to provide access to
    methods, fields and properties. So in most cases you no longer need to
    create wrapping classes.
  • published property was replaced with the implementation of the dir()
    method, so that you can do for example dir(MainForm) to inspect the
    methods, fields and properties of MainForm.
  • Demo 31 has been updated to test/showcase some of the new features.

Study the updated demo 31 to see the improvements.

For example with the following definitions:

type
  TFruit = (Apple, Banana, Orange);
  TFruits = set of TFruit;

TTestRTTIAccess = class
private
  FFruit: TFruit;
  FFruits: TFruits;
public
  FruitField :TFruit;
  FruitsField: TFruits;
  StringField: string;
  DoubleField: double;
  ObjectField : TObject;
  procedure BuyFruits(AFruits: TFruits);
  procedure SetFormCaption(Form: TForm; ACaption: string);
  property Fruit: TFruit read FFruit write FFruit;
  property Fruits: TFruits read FFruits write FFruits;
end;

and the code:

  p := PyDelphiWrapper.Wrap(TTestRTTIAccess.Create, soOwned);
  PythonModule.SetVar( 'rtti_var', p );
  PyEngine.Py_DecRef(p);

You can do in Python:

    def testRttiAccess(self):
        if DelphiVersion >= 15:
          rtti_var.Fruit = 'Apple'
          self.assertTrue(rtti_var.Fruit == 'Apple')
          rtti_var.Fruits = ['Apple', 'Banana']
          self.assertTrue(rtti_var.Fruits == ['Apple', 'Banana'])
          rtti_var.BuyFruits(['Apple', 'Orange'])
          self.assertTrue(rtti_var.Fruits == ['Apple', 'Orange'])
          rtti_var.SetFormCaption(MainForm, 'From TTestRTTIAccess')
          self.assertEqual(MainForm.Caption, 'From TTestRTTIAccess')
          rtti_var.FruitField = 'Apple'
          self.assertTrue(rtti_var.FruitField == 'Apple')
          rtti_var.FruitsField = ['Apple', 'Banana']
          self.assertTrue(rtti_var.FruitsField == ['Apple', 'Banana'])
          rtti_var.StringField = 'Hi'
          self.assertTrue(rtti_var.StringField == 'Hi')
          rtti_var.DoubleField = 3.14
          self.assertTrue(rtti_var.DoubleField == 3.14)
          rtti_var.ObjectField = MainForm
          MainForm.Caption = 'From TTestRTTIAccess.ObjectField'
          self.assertTrue(MainForm.Caption == 'From TTestRTTIAccess.ObjectField')

from python4delphi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.