Difference between revisions of "Python4Delphi"

From Free Pascal wiki
Jump to navigationJump to search
(added my example code)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Current home seems to be https://code.google.com/p/python4delphi/
+
{{LanguageBar}}
 +
= Overview =
 +
 
 +
Current home: https://code.google.com/p/python4delphi/
  
 
From that page:
 
From that page:
Line 13: Line 16:
 
P4D makes it very easy to use python as a scripting language for Delphi applications. It comes with an extensive range of demos and tutorials.
 
P4D makes it very easy to use python as a scripting language for Delphi applications. It comes with an extensive range of demos and tutorials.
 
</blockquote>
 
</blockquote>
 
  
 
The [https://code.google.com/p/python4delphi/source/list changelog] indicates development was last active around Nov 2012.
 
The [https://code.google.com/p/python4delphi/source/list changelog] indicates development was last active around Nov 2012.
  
 +
[https://github.com/pyscripter/python4delphi/commit/88c06f11e70d471fc5dfd3b1e7e446c09eb5ab9a The commit from 21.1.2018 claims the compatibility with both Lazarus and (hopefully) Delphi Linux]
  
 +
= Lazarus port =
  
== (possibly?) related resources ==
+
Lazarus port: [[Using Python in Lazarus on Windows/Linux]]
 
 
* Old wiki (~ 2006) with lots of examples at [http://py4d.pbworks.com/w/page/9174525/FrontPage py4d.pbworks.com]
 
* [https://groups.yahoo.com/neo/groups/pythonfordelphi/info yahoo group]
 
* notes from a [http://www.atug.com/andypatterns/pythonDelphiTalk.htm python for delphi talk].
 
  
 +
= See also =
  
== notes from a user ==
+
* Old wiki (~2006) with lots of examples at [http://py4d.pbworks.com/w/page/9174525/FrontPage py4d.pbworks.com]
 +
* [https://groups.yahoo.com/neo/groups/pythonfordelphi/info Yahoo group]
 +
* Notes from a [http://www.atug.com/andypatterns/pythonDelphiTalk.htm Python for Delphi talk]
  
I was able to get this working on FreeBSD without relying on lazarus design-time components:
+
= FreeBSD =
  
<pre>
+
I was able to get this working on FreeBSD without relying on Lazarus design-time components:
// demo illustrating how to use python for delphi
 
// from plain fpc, without lazarus or anything.
 
  
 +
<syntaxhighlight lang=pascal>
 
program simplefpcdemo;
 
program simplefpcdemo;
 
uses PythonEngine, dynlibs;
 
uses PythonEngine, dynlibs;
Line 48: Line 50:
 
   else writeln('invalid library handle!', dynlibs.GetLoadErrorStr);
 
   else writeln('invalid library handle!', dynlibs.GetLoadErrorStr);
 
end.
 
end.
</pre>
+
</syntaxhighlight>
 +
 
 
The output:
 
The output:
 
<pre>
 
<pre>
Line 55: Line 58:
 
</pre>
 
</pre>
  
My personal working copy (including a python wrapper for my terminal library) is [https://github.com/tangentstorm/py4d @tangentstorm/py4d] on github.
+
My personal working copy (including a Python wrapper for my terminal library) is https://github.com/tangentstorm/py4d .
- tangentstorm
+
 
 +
{{AutoCategory}}
 +
[[Category:Other programming languages]]
 +
[[Category:FreeBSD]]
 +
[[Category:Linux]]
 +
[[Category:Windows]]
 +
[[Category:Python]]

Latest revision as of 13:57, 3 June 2023

English (en) русский (ru)

Overview

Current home: https://code.google.com/p/python4delphi/

From that page:

Python for Delphi (P4D) is a set of free components that wrap up the Python dll into Delphi and Lazarus (FPC). They let you easily execute Python scripts, create new Python modules and new Python types. You can create Python extensions as dlls and much more. P4D provides different levels of functionality:

  • Low-level access to the python API
  • High-level bi-directional interaction with Python
  • Access to Python objects using Delphi custom variants (VarPyth.pas)
  • Wrapping of Delphi objects for use in python scripts using RTTI (WrapDelphi.pas)

P4D makes it very easy to use python as a scripting language for Delphi applications. It comes with an extensive range of demos and tutorials.

The changelog indicates development was last active around Nov 2012.

The commit from 21.1.2018 claims the compatibility with both Lazarus and (hopefully) Delphi Linux

Lazarus port

Lazarus port: Using Python in Lazarus on Windows/Linux

See also

FreeBSD

I was able to get this working on FreeBSD without relying on Lazarus design-time components:

program simplefpcdemo;
uses PythonEngine, dynlibs;

var eng : TPythonEngine;
begin
  eng := TPythonEngine.Create(Nil);
  eng.LoadDll;
  if eng.IsHandleValid then
    begin
      WriteLn(' evens: ', eng.EvalStringAsStr('[x*2 for x in range(10)]'));
      eng.ExecString('print "powers:", [x**2 for x in range(10)]');
    end
  else writeln('invalid library handle!', dynlibs.GetLoadErrorStr);
end.

The output:

    evens: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
   powers: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

My personal working copy (including a Python wrapper for my terminal library) is https://github.com/tangentstorm/py4d .