-
-
Notifications
You must be signed in to change notification settings - Fork 318
/
Copy pathuMain.pas
61 lines (46 loc) · 1.32 KB
/
uMain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
unit uMain;
interface
uses PythonEngine;
function PyInit_DelphiFMX: PPyObject; cdecl;
implementation
uses
System.SysUtils, WrapDelphi, WrapDelphiFMX, PythonDocs;
var
gEngine : TPythonEngine;
gModule : TPythonModule;
gDelphiWrapper : TPyDelphiWrapper;
// This must match the pattern "PyInit_[ProjectName]"
// So if the project is named DelphiFMX then
// the function must be PyInit_DelphiFMX
function PyInit_DelphiFMX: PPyObject;
begin
try
gEngine := TPythonEngine.Create(nil);
gEngine.AutoFinalize := False;
gEngine.UseLastKnownVersion := true;
gModule := TPythonModule.Create(nil);
gModule.Engine := gEngine;
// This must match the ProjectName and the function name pattern
gModule.ModuleName := 'DelphiFMX';
gDelphiWrapper := TPyDelphiWrapper.Create(nil);
gDelphiWrapper.Engine := gEngine;
gDelphiWrapper.Module := gModule;
gEngine.LoadDllInExtensionModule();
except
on E: Exception do begin
WriteLn('An error has occurred: ' + E.Message);
end;
end;
Result := gModule.Module;
end;
initialization
gEngine := nil;
gModule := nil;
gDelphiWrapper := nil;
PyDocServer := TPythonDocServer.Create();
finalization
PyDocServer := nil;
gEngine.Free;
gModule.Free;
gDelphiWrapper.Free;
end.