Skip to content

Commit b487245

Browse files
author
pyscripter
committed
Fixed partially for Unicode
1 parent e814029 commit b487245

File tree

8 files changed

+141
-27
lines changed

8 files changed

+141
-27
lines changed

PythonForDelphi/Demos/Demo29/Project1.dpr

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

36
uses
47
Forms,
58
Unit1 in 'Unit1.pas' {Form1};
69

710
{$R *.res}
8-
11+
{$R XP_UAC.RES}
912
begin
1013
Application.Initialize;
1114
Application.CreateForm(TForm1, Form1);

PythonForDelphi/Demos/Demo29/Project1.dproj

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
<MainSource>Project1.dpr</MainSource>
55
<Config Condition="'$(Config)'==''">Debug</Config>
66
<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
7-
<ProjectVersion>12.0</ProjectVersion>
7+
<ProjectVersion>13.4</ProjectVersion>
8+
<FrameworkType>VCL</FrameworkType>
9+
<Base>True</Base>
10+
<Platform Condition="'$(Platform)'==''">Win32</Platform>
11+
<TargetedPlatforms>1</TargetedPlatforms>
12+
<AppType>Application</AppType>
813
</PropertyGroup>
914
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
1015
<Base>true</Base>
1116
</PropertyGroup>
17+
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
18+
<Base_Win64>true</Base_Win64>
19+
<CfgParent>Base</CfgParent>
20+
<Base>true</Base>
21+
</PropertyGroup>
22+
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
23+
<Base_Win32>true</Base_Win32>
24+
<CfgParent>Base</CfgParent>
25+
<Base>true</Base>
26+
</PropertyGroup>
1227
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
1328
<Cfg_1>true</Cfg_1>
1429
<CfgParent>Base</CfgParent>
@@ -20,11 +35,24 @@
2035
<Base>true</Base>
2136
</PropertyGroup>
2237
<PropertyGroup Condition="'$(Base)'!=''">
23-
<DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;$(DCC_UnitAlias)</DCC_UnitAlias>
38+
<DCC_Namespace>Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace)</DCC_Namespace>
39+
<VerInfo_Locale>4105</VerInfo_Locale>
40+
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
2441
<DCC_DependencyCheckOutputName>Project1.exe</DCC_DependencyCheckOutputName>
2542
<DCC_ImageBase>00400000</DCC_ImageBase>
2643
<DCC_Platform>x86</DCC_Platform>
2744
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Base_Win64)'!=''">
46+
<Icon_MainIcon>Project1_Icon.ico</Icon_MainIcon>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Base_Win32)'!=''">
49+
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
50+
<VerInfo_Locale>1033</VerInfo_Locale>
51+
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
52+
<Icon_MainIcon>Project1_Icon.ico</Icon_MainIcon>
53+
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
54+
<DCC_Namespace>System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
55+
</PropertyGroup>
2856
<PropertyGroup Condition="'$(Cfg_1)'!=''">
2957
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
3058
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
@@ -35,25 +63,25 @@
3563
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
3664
</PropertyGroup>
3765
<ItemGroup>
38-
<DelphiCompile Include="Project1.dpr">
66+
<DelphiCompile Include="$(MainSource)">
3967
<MainSource>MainSource</MainSource>
4068
</DelphiCompile>
4169
<DCCReference Include="Unit1.pas">
4270
<Form>Form1</Form>
4371
</DCCReference>
44-
<BuildConfiguration Include="Base">
45-
<Key>Base</Key>
46-
</BuildConfiguration>
4772
<BuildConfiguration Include="Debug">
4873
<Key>Cfg_2</Key>
4974
<CfgParent>Base</CfgParent>
5075
</BuildConfiguration>
76+
<BuildConfiguration Include="Base">
77+
<Key>Base</Key>
78+
</BuildConfiguration>
5179
<BuildConfiguration Include="Release">
5280
<Key>Cfg_1</Key>
5381
<CfgParent>Base</CfgParent>
5482
</BuildConfiguration>
5583
</ItemGroup>
56-
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
84+
<Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
5785
<ProjectExtensions>
5886
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
5987
<Borland.ProjectType>VCLApplication</Borland.ProjectType>
@@ -95,7 +123,12 @@
95123
<VersionInfoKeys Name="Comments"/>
96124
</VersionInfoKeys>
97125
</Delphi.Personality>
126+
<Platforms>
127+
<Platform value="Win64">False</Platform>
128+
<Platform value="Win32">True</Platform>
129+
</Platforms>
98130
</BorlandProject>
99131
<ProjectFileVersion>12</ProjectFileVersion>
100132
</ProjectExtensions>
133+
<Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
101134
</Project>
1.14 KB
Binary file not shown.

PythonForDelphi/Demos/Demo29/Unit1.dfm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,25 @@ object Form1: TForm1
7272
TabOrder = 3
7373
end
7474
object chkUseDC: TCheckBox
75-
Left = 152
76-
Top = 808
75+
Left = 336
76+
Top = 356
7777
Width = 193
7878
Height = 17
7979
Caption = 'Use Device Context'
80+
Checked = True
81+
State = cbChecked
8082
TabOrder = 4
8183
end
8284
object OpenPictureDialog1: TOpenPictureDialog
8385
Left = 104
8486
Top = 336
8587
end
8688
object PythonEngine1: TPythonEngine
89+
AutoUnload = False
90+
DllName = 'python27.dll'
91+
APIVersion = 1013
92+
RegVersion = '2.7'
93+
UseLastKnownVersion = False
8794
IO = PythonGUIInputOutput1
8895
Left = 168
8996
Top = 624

PythonForDelphi/Demos/Demo29/Unit1.pas

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,46 @@ implementation
3535

3636
{$R *.dfm}
3737

38-
function ImageToString(AGraphic : TGraphic) : String;
38+
// Old code not compatible with Unicode
39+
//
40+
//function ImageToString(AGraphic : TGraphic) : String;
41+
//var
42+
// _stream : TStringStream;
43+
//begin
44+
// _stream := TStringStream.Create('');
45+
// try
46+
// AGraphic.SaveToStream(_stream);
47+
// Result := _stream.DataString;
48+
// finally
49+
// _stream.Free;
50+
// end;
51+
//end;
52+
//
53+
//function BinStrToPyStr(const AString : String) : Variant;
54+
//var
55+
// _str : PPyObject;
56+
//begin
57+
// _str := GetPythonEngine.PyString_FromStringAndSize(PAnsiChar(AString), Length(AString)*SizeOf(Char));
58+
// Result := VarPythonCreate(_str);
59+
// GetPythonEngine.Py_DECREF(_str);
60+
//end;
61+
62+
function ImageToPyStr(AGraphic : TGraphic) : Variant;
3963
var
40-
_stream : TStringStream;
64+
_stream : TMemoryStream;
65+
_str : PPyObject;
4166
begin
42-
_stream := TStringStream.Create('');
67+
_stream := TMemoryStream.Create();
4368
try
44-
AGraphic.SaveToStream(_stream);
45-
Result := _stream.DataString;
69+
AGraphic.SaveToStream(_stream);
70+
_str := GetPythonEngine.PyString_FromStringAndSize(_stream.Memory, _stream.Size);
71+
Result := VarPythonCreate(_str);
72+
GetPythonEngine.Py_DECREF(_str);
4673
finally
4774
_stream.Free;
4875
end;
4976
end;
5077

51-
function BinStrToPyStr(const AString : String) : Variant;
52-
var
53-
_str : PPyObject;
54-
begin
55-
_str := GetPythonEngine.PyString_FromStringAndSize(PAnsiChar(AString), Length(AString));
56-
Result := VarPythonCreate(_str);
57-
GetPythonEngine.Py_DECREF(_str);
58-
end;
59-
6078
procedure TForm1.Button1Click(Sender: TObject);
6179
begin
6280
if OpenPictureDialog1.Execute then
@@ -66,18 +84,28 @@ procedure TForm1.Button1Click(Sender: TObject);
6684
procedure TForm1.Button2Click(Sender: TObject);
6785
var
6886
_im : Variant;
69-
_stream : TStringStream;
87+
_stream : TMemoryStream;
7088
_hdc : Variant;
7189
_dib : Variant;
90+
S : AnsiString;
7291
begin
7392
if (Image1.Picture.Graphic = nil) or Image1.Picture.Graphic.Empty then
7493
raise Exception.Create('You must first select an image');
7594
PythonEngine1.ExecStrings(Memo1.Lines);
76-
_im := MainModule.ProcessImage(BinStrToPyStr(ImageToString(Image1.Picture.Graphic)));
95+
_im := MainModule.ProcessImage(ImageToPyStr(Image1.Picture.Graphic));
7796
if not chkUseDC.Checked then
7897
begin
79-
_stream := TStringStream.Create(MainModule.ImageToString(_im));
98+
{
99+
TODO :
100+
Needs fixing. Probably has to do with images containing null bytes which
101+
cannot be converted to ansistrings.
102+
}
103+
ShowMessage('This does not work and needs fixing');
104+
_stream := TMemoryStream.Create();
80105
try
106+
S := MainModule.ImageToString(_im);
107+
_stream.Write(PAnsiChar(S)^, Length(S));
108+
_stream.Position := 0;
81109
Image1.Picture.Graphic.LoadFromStream(_stream);
82110
finally
83111
_stream.Free;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
<assemblyIdentity
4+
version="1.0.0.0"
5+
processorArchitecture="*"
6+
name="PyScripter"
7+
type="win32"/>
8+
<dependency>
9+
<dependentAssembly>
10+
<assemblyIdentity
11+
type="win32"
12+
name="Microsoft.Windows.Common-Controls"
13+
version="6.0.0.0"
14+
processorArchitecture="*"
15+
publicKeyToken="6595b64144ccf1df"
16+
language="*"/>
17+
</dependentAssembly>
18+
</dependency>
19+
<dependency>
20+
<dependentAssembly>
21+
<assemblyIdentity
22+
type="win32"
23+
name="Microsoft.VC90.CRT"
24+
version="9.0.21022.8"
25+
processorArchitecture="x86"
26+
publicKeyToken="1fc8b3b9a1e18e3b"
27+
language="*"/>
28+
</dependentAssembly>
29+
</dependency>
30+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
31+
<security>
32+
<requestedPrivileges>
33+
<requestedExecutionLevel level="asInvoker"/>
34+
</requestedPrivileges>
35+
</security>
36+
</trustInfo>
37+
<asmv3:application>
38+
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
39+
<dpiAware>true</dpiAware>
40+
</asmv3:windowsSettings>
41+
</asmv3:application>
42+
</assembly>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 24 ".\XP_UAC.manifest"
1.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)