@@ -292,7 +292,7 @@ function ShiftToPython(AShift : TShiftState) : PPyObject;
292292 begin
293293 with GetPythonEngine do
294294 begin
295- _item := PyString_FromString(PAnsiChar(AnsiString( AString)) );
295+ _item := PyString_FromDelphiString( AString);
296296 PyList_Append(AList, _item);
297297 Py_XDecRef(_item);
298298 end ;
@@ -338,15 +338,12 @@ function TPyDelphiPersistent.Assign_Wrapper(args: PPyObject): PPyObject;
338338var
339339 _obj : PPyObject;
340340begin
341- with GetPythonEngine do
342- begin
343- // We adjust the transmitted self argument
344- Adjust(@Self);
345- if PyArg_ParseTuple( args, ' O:Assign' ,@_obj ) <> 0 then
346- Result := Self.Assign(_obj)
347- else
348- Result := nil ;
349- end ;
341+ // We adjust the transmitted self argument
342+ Adjust(@Self);
343+ if GetPythonEngine.PyArg_ParseTuple( args, ' O:Assign' ,@_obj ) <> 0 then
344+ Result := Self.Assign(_obj)
345+ else
346+ Result := nil ;
350347end ;
351348
352349class function TPyDelphiPersistent.DelphiObjectClass : TClass;
@@ -362,11 +359,11 @@ function TPyDelphiPersistent.GetDelphiObject: TPersistent;
362359function TPyDelphiPersistent.GetNamePath_Wrapper (
363360 args: PPyObject): PPyObject;
364361begin
362+ // We adjust the transmitted self argument
363+ Adjust(@Self);
365364 with GetPythonEngine do begin
366- // We adjust the transmitted self argument
367- Adjust(@Self);
368365 if PyArg_ParseTuple( args, ' :GetNamePath' ) <> 0 then begin
369- Result := PyString_FromString(PAnsiChar(AnsiString( DelphiObject.GetNamePath)) )
366+ Result := PyString_FromDelphiString( DelphiObject.GetNamePath)
370367 end else
371368 Result := nil ;
372369 end ;
@@ -536,28 +533,22 @@ function TPyDelphiCollection.GetDelphiObject: TCollection;
536533
537534function TPyDelphiCollection.Get_Count (AContext: Pointer): PPyObject;
538535begin
539- with GetPythonEngine do begin
540- Adjust(@Self);
541- Result := PyInt_FromLong(DelphiObject.Count);
542- end ;
536+ Adjust(@Self);
537+ Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Count);
543538end ;
544539
545540function TPyDelphiCollection.Get_Items (AContext: Pointer): PPyObject;
546541begin
547- with GetPythonEngine do begin
548- Adjust(@Self);
549- Result := Self.PyDelphiWrapper.DefaultContainerType.CreateInstance;
550- with PythonToDelphi(Result) as TPyDelphiContainer do
551- Setup(Self.PyDelphiWrapper, Self.ContainerAccess.Clone);
552- end ;
542+ Adjust(@Self);
543+ Result := Self.PyDelphiWrapper.DefaultContainerType.CreateInstance;
544+ with PythonToDelphi(Result) as TPyDelphiContainer do
545+ Setup(Self.PyDelphiWrapper, Self.ContainerAccess.Clone);
553546end ;
554547
555548function TPyDelphiCollection.Get_Owner (AContext: Pointer): PPyObject;
556549begin
557- with GetPythonEngine do begin
558- Adjust(@Self);
559- Result := Wrap(DelphiObject.Owner);
560- end ;
550+ Adjust(@Self);
551+ Result := Wrap(DelphiObject.Owner);
561552end ;
562553
563554function TPyDelphiCollection.Insert_Wrapper (args: PPyObject): PPyObject;
@@ -730,10 +721,10 @@ function TPyDelphiComponent.BindMethodsToEvents(args: PPyObject): PPyObject;
730721 _bindings : PPyObject;
731722 _type : PPyTypeObject;
732723begin
724+ Adjust(@Self);
733725 _prefix := ' handle_' ;
734726 with GetPythonEngine do begin
735727 // We adjust the transmitted self argument
736- Adjust(@Self);
737728 Result := nil ;
738729 s := nil ;
739730 if PyArg_ParseTuple( args, ' |O:BindMethodsToEvents' ,@s ) <> 0 then
@@ -808,8 +799,8 @@ function TPyDelphiComponent.BindMethodsToEvents(args: PPyObject): PPyObject;
808799 else
809800 begin
810801 _pair := PyTuple_New(3 );
811- PyTuple_SetItem(_pair, 0 , PyString_FromString(PAnsiChar(AnsiString( _compName)) ));
812- PyTuple_SetItem(_pair, 1 , PyString_FromString(PAnsiChar(AnsiString( _eventName)) ));
802+ PyTuple_SetItem(_pair, 0 , PyString_FromDelphiString( _compName));
803+ PyTuple_SetItem(_pair, 1 , PyString_FromDelphiString( _eventName));
813804 PyTuple_SetItem(_pair, 2 , objMethod);
814805 PyList_Append(_bindings, _pair);
815806 end ;
@@ -839,36 +830,30 @@ function TPyDelphiComponent.BindMethodsToEvents(args: PPyObject): PPyObject;
839830
840831function TPyDelphiComponent.Get_ComponentCount (AContext: Pointer): PPyObject;
841832begin
842- with GetPythonEngine do begin
843- Adjust(@Self);
844- Result := PyInt_FromLong(DelphiObject.ComponentCount);
845- end ;
833+ Adjust(@Self);
834+ Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ComponentCount);
846835end ;
847836
848837function TPyDelphiComponent.Get_Components (AContext: Pointer): PPyObject;
849838begin
850- with GetPythonEngine do begin
851- Adjust(@Self);
852- Result := Self.PyDelphiWrapper.DefaultContainerType.CreateInstance;
853- with PythonToDelphi(Result) as TPyDelphiContainer do
854- Setup(Self.PyDelphiWrapper, Self.ContainerAccess.Clone);
855- end ;
839+ Adjust(@Self);
840+ Result := Self.PyDelphiWrapper.DefaultContainerType.CreateInstance;
841+ with PythonToDelphi(Result) as TPyDelphiContainer do
842+ Setup(Self.PyDelphiWrapper, Self.ContainerAccess.Clone);
856843end ;
857844
858845function TPyDelphiComponent.Get_Owner (AContext: Pointer): PPyObject;
859846begin
860- with GetPythonEngine do begin
861- Adjust(@Self);
862- Result := Wrap(DelphiObject.Owner);
863- end ;
847+ Adjust(@Self);
848+ Result := Wrap(DelphiObject.Owner);
864849end ;
865850
866851function TPyDelphiComponent.GetParentComponent_Wrapper (
867852 args: PPyObject): PPyObject;
868853begin
854+ Adjust(@Self);
869855 with GetPythonEngine do begin
870856 // We adjust the transmitted self argument
871- Adjust(@Self);
872857 if PyArg_ParseTuple( args, ' :GetParentComponent' ) <> 0 then begin
873858 Result := Wrap(DelphiObject.GetParentComponent)
874859 end else
@@ -878,9 +863,9 @@ function TPyDelphiComponent.GetParentComponent_Wrapper(
878863
879864function TPyDelphiComponent.HasParent_Wrapper (args: PPyObject): PPyObject;
880865begin
866+ Adjust(@Self);
881867 with GetPythonEngine do begin
882868 // We adjust the transmitted self argument
883- Adjust(@Self);
884869 if PyArg_ParseTuple( args, ' :HasParent' ) <> 0 then begin
885870 Result := VariantAsPyObject(DelphiObject.HasParent)
886871 end else
@@ -1071,7 +1056,7 @@ function TStringsAccess.GetContainer: TStrings;
10711056
10721057function TStringsAccess.GetItem (AIndex: Integer): PPyObject;
10731058begin
1074- Result := GetPythonEngine.PyString_FromString( PAnsiChar(AnsiString( Container[AIndex])) );
1059+ Result := GetPythonEngine.PyString_FromDelphiString( Container[AIndex] );
10751060end ;
10761061
10771062function TStringsAccess.GetSize : Integer;
@@ -1302,28 +1287,24 @@ function TPyDelphiStrings.GetDelphiObject: TStrings;
13021287
13031288function TPyDelphiStrings.Get_Capacity (AContext: Pointer): PPyObject;
13041289begin
1305- with GetPythonEngine do begin
1306- Adjust(@Self);
1307- Result := PyInt_FromLong(DelphiObject.Capacity);
1308- end ;
1290+ Adjust(@Self);
1291+ Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Capacity);
13091292end ;
13101293
13111294function TPyDelphiStrings.Get_Objects (AContext: Pointer): PPyObject;
13121295begin
1313- with GetPythonEngine do begin
1314- Adjust(@Self);
1315- Result := Self.PyDelphiWrapper.DefaultContainerType.CreateInstance;
1316- with PythonToDelphi(Result) as TPyDelphiContainer do
1317- Setup(Self.PyDelphiWrapper, TStringsObjectsAccess.Create(Self.PyDelphiWrapper, Self.DelphiObject));
1318- end ;
1296+ Adjust(@Self);
1297+ Result := Self.PyDelphiWrapper.DefaultContainerType.CreateInstance;
1298+ with PythonToDelphi(Result) as TPyDelphiContainer do
1299+ Setup(Self.PyDelphiWrapper, TStringsObjectsAccess.Create(Self.PyDelphiWrapper,
1300+ Self.DelphiObject));
13191301end ;
13201302
13211303function TPyDelphiStrings.Get_Text (AContext: Pointer): PPyObject;
13221304begin
1323- with GetPythonEngine do begin
1324- Adjust(@Self);
1325- Result := PyString_FromString(PAnsiChar(GetPythonEngine.CleanString(AnsiString(DelphiObject.Text))));
1326- end ;
1305+ Adjust(@Self);
1306+ Result := GetPythonEngine.PyString_FromDelphiString(
1307+ AdjustLineBreaks(DelphiObject.Text, tlbsLF));
13271308end ;
13281309
13291310function TPyDelphiStrings.IndexOf_Wrapper (args: PPyObject): PPyObject;
@@ -1438,9 +1419,8 @@ class procedure TPyDelphiStrings.RegisterMethods(PythonType: TPythonType);
14381419
14391420function TPyDelphiStrings.Repr : PPyObject;
14401421begin
1441- with GetPythonEngine do
1442- Result := PyString_FromString( PAnsiChar(AnsiString(Format(' <Delphi TStrings at %x>' ,
1443- [NativeInt(self)]))) );
1422+ Result := GetPythonEngine.PyString_FromDelphiString( Format(' <Delphi TStrings at %x>' ,
1423+ [NativeInt(self)]) );
14441424end ;
14451425
14461426function TPyDelphiStrings.SaveToFile_Wrapper (args: PPyObject): PPyObject;
0 commit comments