Skip to content

Commit c453dea

Browse files
author
pyscripter
committed
Adapted to work with Python 3.x
1 parent d150751 commit c453dea

5 files changed

Lines changed: 33 additions & 1 deletion

File tree

PythonForDelphi/Demos/Demo09/Project1.dpr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
2+
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
3+
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
14
program Project1;
25

36
{$I Definition.Inc}
792 Bytes
Binary file not shown.

PythonForDelphi/Demos/Demo09/demodll.dpr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
2+
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
3+
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
14
library demodll;
25

36
{$I Definition.Inc}
@@ -8,7 +11,8 @@ uses
811
module in 'module.pas';
912

1013
exports
11-
initdemodll;
14+
initdemodll,
15+
PyInit_demodll;
1216
{$IFDEF MSWINDOWS}
1317
{$E pyd}
1418
{$ENDIF}

PythonForDelphi/Demos/Demo09/demodll.dproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<Parameters Name="UseLauncher">False</Parameters>
6666
<Parameters Name="LoadAllSymbols">True</Parameters>
6767
<Parameters Name="LoadUnspecifiedSymbols">False</Parameters>
68+
<Parameters Name="HostApplication">C:\Delphi\progs32\Python\P4D\PythonForDelphi\Demos\Demo09\Project1.exe</Parameters>
6869
</Parameters>
6970
<VersionInfo>
7071
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>

PythonForDelphi/Demos/Demo09/module.pas

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
interface
44
uses PythonEngine;
55

6+
// for python 2.x
67
procedure initdemodll; cdecl;
8+
// for python 3.x
9+
function PyInit_demodll : PPyObject; cdecl;
710

811
var
912
gEngine : TPythonEngine;
@@ -41,6 +44,27 @@ procedure initdemodll;
4144
end;
4245
end;
4346

47+
function PyInit_demodll : PPyObject;
48+
begin
49+
Result := nil;
50+
try
51+
gEngine := TPythonEngine.Create(nil);
52+
gEngine.AutoFinalize := False;
53+
gEngine.UseLastKnownVersion := False;
54+
gEngine.RegVersion := '3.2'; //<-- Use the same version as the python 3.x your main program uses
55+
gEngine.APIVersion := 1013;
56+
gEngine.DllName := 'python32.dll';
57+
gEngine.LoadDll;
58+
gModule := TPythonModule.Create(nil);
59+
gModule.Engine := gEngine;
60+
gModule.ModuleName := 'demodll';
61+
gModule.AddMethod( 'add', @Add, 'add(a,b) -> a+b' );
62+
gModule.Initialize;
63+
Result := gModule.Module;
64+
except
65+
end;
66+
end;
67+
4468
initialization
4569
finalization
4670
gEngine.Free;

0 commit comments

Comments
 (0)