donald7771 / python4delphi

Automatically exported from code.google.com/p/python4delphi
0 stars 0 forks source link

Suggestion - make exposing Delphi objects to python painless by utilizing the new RTTI feature in D2010 (and above) #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I've a suggestion - make exposing Delphi objects to python painless by 
utilizing the new RTTI (runtime type information) feature in D2010 (and above).

Currently exposing a class to the hosted Python code needs to you to write too 
much code (check demo06), I guess if we take advantage of the new RTTI feature 
in the newer versions of Delphi, the process can be improved a lot.

For example, check out the Delphi chromium embedded project, all you have to do 
to expose the interface of any Delphi class to the JavaScript environment, is 
to register the class:

// this is your class exposed to JS 
  Test = class 
    class procedure doit(const v: string); 
  end; 

initialization 
// Register your class 
  TCefRTTIExtension.Register('app', Test);

// and in JavaScript code to call that class above:
app.doit(''foo'')', '', 0); 

Cool! Isn't it?

The above code was extracted from: 
http://groups.google.com/group/delphichromiumembedded/browse_thread/thread/1793e
7ca66012f0c/8ab31a5ecdb6bf48?lnk=gst&q=JavaScript+return+#

Some intro about RTTI introduced since D2010:
http://robstechcorner.blogspot.com/2009/09/delphi-2010-rtti-basics.html

Original issue reported on code.google.com by edwin....@innovationgear.com on 29 Oct 2011 at 8:50

GoogleCodeExporter commented 9 years ago
Issue 18 has been merged into this issue.

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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Thanks for the hint! It's much easier then Demo08.

Original comment by edwin....@innovationgear.com on 10 Nov 2011 at 1:21

GoogleCodeExporter commented 9 years ago
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 alexandre@katrid.com on 28 Jan 2012 at 4:52

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, I will review the changes and merge them.

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

GoogleCodeExporter commented 9 years ago
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 cho...@gmail.com on 4 Feb 2012 at 10:12

GoogleCodeExporter commented 9 years ago
Sounds great!

Original comment by edwin....@innovationgear.com on 5 Mar 2012 at 9:00

GoogleCodeExporter commented 9 years ago
@ pyscripter, 

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

Original comment by edwin....@innovationgear.com on 26 May 2012 at 8:53