Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Demos/Demo34/Demo34.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
<UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
Expand All @@ -87,6 +88,8 @@
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
Expand Down
Binary file modified Demos/Demo34/Unit1.dfm
Binary file not shown.
33 changes: 14 additions & 19 deletions Demos/Demo34/Unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure cbPyVersionsSelect(Sender: TObject);
private
{ Déclarations privées }
PythonEngine1: TPythonEngine;
PythonModule1: TPythonModule;
PythonType1: TPythonType;
PyVersions: TPythonVersions;
public
{ Déclarations publiques }
procedure CreatePythonComponents;
end;

Expand All @@ -40,8 +38,8 @@ TForm1 = class(TForm)
// Then it must override some methods, like the constructors,
// the RegisterMethods and the type services' virtual methods.
TPyPoint = class(TPyObject)
x, y : Integer;
Name : String;
x, y: Integer;
Name: String;

// Constructors & Destructors
constructor Create( APythonType : TPythonType ); override;
Expand Down Expand Up @@ -96,7 +94,6 @@ procedure TForm1.CreatePythonComponents;

PythonEngine1.IO := PythonGUIInputOutput1;


{ TPythonModule }
PythonModule1 := TPythonModule.Create(Self);

Expand Down Expand Up @@ -131,8 +128,8 @@ procedure TForm1.CreatePythonComponents;
end;

procedure TForm1.FormCreate(Sender: TObject);
Var
PyVersion : TPythonVersion;
var
PyVersion: TPythonVersion;
begin
PyVersions := GetRegisteredPythonVersions;
for PyVersion in PyVersions do
Expand All @@ -143,7 +140,6 @@ procedure TForm1.FormCreate(Sender: TObject);
end;
end;


// First, we need to initialize the property PyObjectClass with
// the class of our Type object
procedure TForm1.PythonType1Initialization(Sender: TObject);
Expand All @@ -163,7 +159,7 @@ constructor TPyPoint.Create( APythonType : TPythonType );
// Don't call the Create constructor of TPyPoint, because
// we call the inherited constructor CreateWith that calls
// the Create constructor first, and because the constructors
// are virtual, TPyPoint.Create will be automatically be called.
// are virtual, TPyPoint.Create will automatically be called.

constructor TPyPoint.CreateWith( PythonType : TPythonType; args : PPyObject );
begin
Expand Down Expand Up @@ -257,16 +253,16 @@ procedure TPyPoint.OffsetBy( dx, dy : Integer );

function TPyPoint.DoOffsetBy( args : PPyObject ) : PPyObject;
var
dx, dy : Integer;
dx, dy: Integer;
begin
with GetPythonEngine do
begin
// We adjust the transmitted self argument
Adjust(@Self);
// first we extract the arguments
if PyArg_ParseTuple( args, 'ii:Point.Offset',@dx, @dy ) <> 0 then
if PyArg_ParseTuple( args, 'ii:Point.Offset', @dx, @dy ) <> 0 then
begin
// if it's ok, then we call the method that does the job
// if it's ok, we call the method that does the job
// with the correct arguments
OffsetBy( dx, dy );
// Finally, we return nothing
Expand Down Expand Up @@ -299,16 +295,15 @@ function TPyPoint.DoRaiseError( args : PPyObject ) : PPyObject;

/////////////////////////////////////////////////


procedure TForm1.Button1Click(Sender: TObject);
var
DelphiPoint : TPyPoint;
p : PPyObject;
DelphiPoint: TPyPoint;
p: PPyObject;
begin
// Here's how you can create/read Python vars from Delphi with
// Delphi/Python objects.

// You should ask to the TPythonType to create an instance of its type
// You should ask the TPythonType to create an instance of its type
// because it will do some initialization. You can use CreateInstanceWith
// if you want to transmit some Python arguments.
// We receive a Python object pointer
Expand All @@ -317,10 +312,10 @@ procedure TForm1.Button1Click(Sender: TObject);
// Then we cast the python object to the right delphi type
DelphiPoint := TPyPoint( PythonToDelphi(p) );
// We do some changes on the delphi object
DelphiPoint.X:=10;
DelphiPoint.Y:=20;
DelphiPoint.X := 10;
DelphiPoint.Y := 20;
// Add variable "myPoint" in the module "spam".
// So you'll access to the var in the module called spam with:
// So you'll have access to the var in the module called spam with:
// import spam
// print spam.myPoint
PythonModule1.SetVar( 'myPoint', p );
Expand Down