@@ -1527,8 +1527,8 @@ function TExposedGetSet.GetterWrapper(AObj: PPyObject; AContext : Pointer): PPyO
15271527
15281528 if not Assigned(Result) then
15291529 with GetPythonEngine do
1530- PyErr_SetObject (PyExc_AttributeError^,
1531- PyUnicodeFromString( Format(rs_ErrAttrGet, [FRttiMember.Name , LOutMsg])));
1530+ PyErr_SetString (PyExc_AttributeError^,
1531+ PAnsiChar(EncodeString( Format(rs_ErrAttrGet, [FRttiMember.Name , LOutMsg]) )));
15321532end ;
15331533
15341534function TExposedGetSet.SetterWrapper (AObj, AValue: PPyObject; AContext: Pointer): Integer; cdecl;
@@ -1552,8 +1552,8 @@ function TExposedGetSet.SetterWrapper(AObj, AValue: PPyObject; AContext: Pointer
15521552
15531553 if Result <> 0 then
15541554 with GetPythonEngine do
1555- PyErr_SetObject (PyExc_AttributeError^,
1556- PyUnicodeFromString( Format(rs_ErrAttrSet, [FRttiMember.Name , ErrMsg])));
1555+ PyErr_SetString (PyExc_AttributeError^,
1556+ PAnsiChar(EncodeString( Format(rs_ErrAttrSet, [FRttiMember.Name , ErrMsg]) )));
15571557end ;
15581558
15591559{ TExposedField }
@@ -1648,8 +1648,8 @@ function TExposedEvent.SetterWrapper(AObj, AValue: PPyObject; AContext: Pointer)
16481648
16491649 if Result <> 0 then
16501650 with GetPythonEngine do
1651- PyErr_SetObject (PyExc_AttributeError^,
1652- PyUnicodeFromString( Format(rs_ErrAttrSet, [FRttiMember.Name , ErrMsg])));
1651+ PyErr_SetString (PyExc_AttributeError^,
1652+ PAnsiChar(EncodeString( Format(rs_ErrAttrSet, [FRttiMember.Name , ErrMsg]) )));
16531653end ;
16541654
16551655{ TExposedIndexedProperty }
@@ -1745,7 +1745,7 @@ function TPyIndexedProperty.MpAssSubscript(obj1, obj2: PPyObject) : Integer;
17451745 if not FProperty.IsWritable then
17461746 begin
17471747 with Engine do
1748- PyErr_SetObject (PyExc_TypeError^, PyUnicodeFromString( rs_NotWritable));
1748+ PyErr_SetString (PyExc_TypeError^, PAnsiChar(EncodeString( rs_NotWritable) ));
17491749 Exit;
17501750 end ;
17511751
@@ -1869,8 +1869,8 @@ class procedure TRttiEventHandler.ImplCallback(UserData: Pointer;
18691869 if Assigned(PyResult) and (EventHandler.MethodType.ReturnType <> nil ) and
18701870 not PyObjectToTValue(PyResult, EventHandler.MethodType.ReturnType, Result, ErrMsg)
18711871 then
1872- Engine.PyErr_SetObject (Engine.PyExc_TypeError^, Engine.PyUnicodeFromString (
1873- Format(rs_ErrInvalidRet, [string(EventHandler.PropertyInfo.Name ), ErrMsg])));
1872+ Engine.PyErr_SetString (Engine.PyExc_TypeError^, PAnsiChar( Engine.EncodeString (
1873+ Format(rs_ErrInvalidRet, [string(EventHandler.PropertyInfo.Name ), ErrMsg])))) ;
18741874 Engine.Py_XDECREF(PyResult);
18751875 finally
18761876 Engine.Py_XDECREF(PyArgs);
@@ -1904,9 +1904,8 @@ function GlobalDelphiWrapper: TPyDelphiWrapper;
19041904procedure InvalidArguments (const MethName, ErrMsg : string);
19051905begin
19061906 with GetPythonEngine do
1907- PyErr_SetObject(PyExc_TypeError^, PyUnicodeFromString(
1908- Format(rs_ErrInvalidArgs,
1909- [MethName, ErrMsg])));
1907+ PyErr_SetString(PyExc_TypeError^, PAnsiChar(EncodeString(
1908+ Format(rs_ErrInvalidArgs, [MethName, ErrMsg]))));
19101909end ;
19111910
19121911function ValidateClassRef (PyValue: PPyObject; RefClass: TClass;
@@ -2354,8 +2353,8 @@ function CheckIndex(AIndex, ACount : Integer; const AIndexName : string = 'Index
23542353 with GetPythonEngine do
23552354 begin
23562355 Result := False;
2357- PyErr_SetObject (PyExc_IndexError^, PyUnicodeFromString (
2358- Format(rs_ErrCheckIndex,[AIndexName, AIndex])));
2356+ PyErr_SetString (PyExc_IndexError^, PAnsiChar(EncodeString (
2357+ Format(rs_ErrCheckIndex,[AIndexName, AIndex])))) ;
23592358 end
23602359 else
23612360 Result := True;
@@ -2372,8 +2371,8 @@ function CheckIntAttribute(AAttribute : PPyObject; const AAttributeName : string
23722371 begin
23732372 Result := False;
23742373 with GetPythonEngine do
2375- PyErr_SetObject (PyExc_AttributeError^,
2376- PyUnicodeFromString( Format(rs_ErrCheckInt, [AAttributeName])));
2374+ PyErr_SetString (PyExc_AttributeError^,
2375+ PAnsiChar(EncodeString( Format(rs_ErrCheckInt, [AAttributeName]) )));
23772376 end ;
23782377end ;
23792378
@@ -2388,8 +2387,8 @@ function CheckFloatAttribute(AAttribute : PPyObject; const AAttributeName : stri
23882387 begin
23892388 Result := False;
23902389 with GetPythonEngine do
2391- PyErr_SetObject (PyExc_AttributeError^,
2392- PyUnicodeFromString( Format(rs_ErrCheckFloat, [AAttributeName])));
2390+ PyErr_SetString (PyExc_AttributeError^,
2391+ PAnsiChar(EncodeString( Format(rs_ErrCheckFloat, [AAttributeName]) )));
23932392 end ;
23942393end ;
23952394
@@ -2410,8 +2409,8 @@ function CheckStrAttribute(AAttribute : PPyObject; const AAttributeName : string
24102409 begin
24112410 Result := False;
24122411 with GetPythonEngine do
2413- PyErr_SetObject (PyExc_AttributeError^,
2414- PyUnicodeFromString( Format(rs_ErrCheckStr, [AAttributeName])));
2412+ PyErr_SetString (PyExc_AttributeError^,
2413+ PAnsiChar(EncodeString( Format(rs_ErrCheckStr, [AAttributeName]) )));
24152414 end ;
24162415end ;
24172416
@@ -2423,8 +2422,8 @@ function CheckCallableAttribute(AAttribute : PPyObject; const AAttributeName : s
24232422 begin
24242423 Result := False;
24252424 with GetPythonEngine do
2426- PyErr_SetObject (PyExc_AttributeError^,
2427- PyUnicodeFromString( Format(rs_ErrCheckCallable, [AAttributeName])));
2425+ PyErr_SetString (PyExc_AttributeError^,
2426+ PAnsiChar(EncodeString( Format(rs_ErrCheckCallable, [AAttributeName]) )));
24282427 end ;
24292428end ;
24302429
@@ -2436,9 +2435,9 @@ function CheckEnum(const AEnumName : string; AValue, AMinValue, AMaxValue : Int
24362435 begin
24372436 Result := False;
24382437 with GetPythonEngine do
2439- PyErr_SetObject (PyExc_AttributeError^,
2440- PyUnicodeFromString (Format(rs_ErrCheckEnum,
2441- [AEnumName, AMinValue, AMaxValue, AValue])));
2438+ PyErr_SetString (PyExc_AttributeError^,
2439+ PAnsiChar(EncodeString (Format(rs_ErrCheckEnum,
2440+ [AEnumName, AMinValue, AMaxValue, AValue])))) ;
24422441 end ;
24432442end ;
24442443
@@ -2461,8 +2460,8 @@ function CheckObjAttribute(AAttribute : PPyObject; const AAttributeName : string
24612460 begin
24622461 Result := False;
24632462 with GetPythonEngine do
2464- PyErr_SetObject (PyExc_AttributeError^,
2465- PyUnicodeFromString( Format(rs_ErrCheckObjOfType, [AAttributeName, AExpectedClass.ClassName])));
2463+ PyErr_SetString (PyExc_AttributeError^,
2464+ PAnsiChar(EncodeString( Format(rs_ErrCheckObjOfType, [AAttributeName, AExpectedClass.ClassName]) )));
24662465 end
24672466 else
24682467 begin
@@ -2474,8 +2473,8 @@ function CheckObjAttribute(AAttribute : PPyObject; const AAttributeName : string
24742473 begin
24752474 Result := False;
24762475 with GetPythonEngine do
2477- PyErr_SetObject (PyExc_AttributeError^,
2478- PyUnicodeFromString( Format(rs_ErrCheckObj, [AAttributeName])));
2476+ PyErr_SetString (PyExc_AttributeError^,
2477+ PAnsiChar(EncodeString( Format(rs_ErrCheckObj, [AAttributeName]) )));
24792478 end ;
24802479end ;
24812480
@@ -2815,8 +2814,8 @@ function TPyDelphiContainer.SqAssItem(idx: NativeInt;
28152814 begin
28162815 Result := -1 ;
28172816 with GetPythonEngine do
2818- PyErr_SetObject ( PyExc_SystemError^,
2819- PyUnicodeFromString( Format(rs_ErrSqAss, [fContainerAccess.Name ])) );
2817+ PyErr_SetString ( PyExc_SystemError^,
2818+ PAnsiChar(EncodeString( Format(rs_ErrSqAss, [fContainerAccess.Name ]))) );
28202819 end ;
28212820end ;
28222821
@@ -2833,8 +2832,8 @@ function TPyDelphiContainer.SqContains(obj: PPyObject): integer;
28332832 begin
28342833 Result := -1 ;
28352834 with GetPythonEngine do
2836- PyErr_SetObject( PyExc_SystemError^,
2837- PyUnicodeFromString( Format(rs_ErrSqContains, [fContainerAccess.Name ])) );
2835+ PyErr_SetString( PyExc_SystemError^,
2836+ PAnsiChar(EncodeString( Format(rs_ErrSqContains, [fContainerAccess.Name ]))) );
28382837 end ;
28392838end ;
28402839
@@ -2928,8 +2927,8 @@ function TPyDelphiObject.CheckBound: Boolean;
29282927 Result := Assigned(DelphiObject);
29292928 if not Result then
29302929 with GetPythonEngine do
2931- PyErr_SetObject (PyExc_AttributeError^,
2932- PyUnicodeFromString( Format(rs_ErrCheckBound, [ClassName])));
2930+ PyErr_SetString (PyExc_AttributeError^,
2931+ PAnsiChar(EncodeString( Format(rs_ErrCheckBound, [ClassName]) )));
29332932end ;
29342933
29352934function TPyDelphiObject.Compare (obj: PPyObject): Integer;
@@ -2959,8 +2958,8 @@ constructor TPyDelphiObject.Create(APythonType: TPythonType);
29592958constructor TPyDelphiObject.CreateWith(APythonType: TPythonType; args, kwds: PPyObject);
29602959begin
29612960 with APythonType.Engine do
2962- PyErr_SetObject (PyExc_TypeError^, PyUnicodeFromString (
2963- Format(rs_CannotCreate, [APythonType.TypeName])));
2961+ PyErr_SetString (PyExc_TypeError^, PAnsiChar(EncodeString (
2962+ Format(rs_CannotCreate, [APythonType.TypeName])))) ;
29642963end ;
29652964
29662965function TPyDelphiObject.CreateContainerAccess : TContainerAccess;
@@ -3189,8 +3188,8 @@ function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
31893188
31903189 if Result = nil then
31913190 with DelphiWrapper.Engine do
3192- PyErr_SetObject (PyExc_TypeError^, PyUnicodeFromString (
3193- Format(rs_ErrInvalidRet, [Method.Name , ErrMsg])));
3191+ PyErr_SetString (PyExc_TypeError^, PAnsiChar(EncodeString (
3192+ Format(rs_ErrInvalidRet, [Method.Name , ErrMsg])))) ;
31943193 except
31953194 on E: Exception do begin
31963195 Result := nil ;
@@ -3405,8 +3404,8 @@ function TPyRttiObject.GetAttrO(key: PPyObject): PPyObject;
34053404 Result := GetRttiAttr(fAddr, RttiType, KeyName, PyDelphiWrapper, ErrMsg);
34063405 if not Assigned(Result) then
34073406 with GetPythonEngine do
3408- PyErr_SetObject (PyExc_AttributeError^,
3409- PyUnicodeFromString( Format(rs_ErrAttrGet,[KeyName, ErrMsg])));
3407+ PyErr_SetString (PyExc_AttributeError^,
3408+ PAnsiChar(EncodeString( Format(rs_ErrAttrGet,[KeyName, ErrMsg]) )));
34103409end ;
34113410
34123411class procedure TPyRttiObject.RegisterMethods (PythonType: TPythonType);
@@ -3436,8 +3435,8 @@ function TPyRttiObject.SetAttrO(key, value: PPyObject): Integer;
34363435
34373436 if Result <> 0 then
34383437 with GetPythonEngine do
3439- PyErr_SetObject (PyExc_AttributeError^, PyUnicodeFromString (
3440- Format(rs_ErrAttrSet, [KeyName, ErrMsg])));
3438+ PyErr_SetString (PyExc_AttributeError^, PAnsiChar(EncodeString (
3439+ Format(rs_ErrAttrSet, [KeyName, ErrMsg])))) ;
34413440end ;
34423441
34433442function TPyRttiObject.SetProps (args, keywords: PPyObject): PPyObject;
@@ -3564,8 +3563,8 @@ function TPyDelphiObject.GetAttrO(key: PPyObject): PPyObject;
35643563 // If DelphiObject is nil exit immediately with an error
35653564 if not Assigned(DelphiObject) then
35663565 begin
3567- PyEngine.PyErr_SetObject (PyEngine.PyExc_AttributeError^,
3568- PyEngine.PyUnicodeFromString (rs_ErrObjectDestroyed));
3566+ PyEngine.PyErr_SetString (PyEngine.PyExc_AttributeError^,
3567+ PAnsiChar( PyEngine.EncodeString (rs_ErrObjectDestroyed) ));
35693568 Exit;
35703569 end ;
35713570
@@ -3652,8 +3651,8 @@ function TPyDelphiObject.GetAttrO(key: PPyObject): PPyObject;
36523651 end ;
36533652{ $ENDIF}
36543653 if not Assigned(Result) then
3655- PyEngine.PyErr_SetObject (PyEngine.PyExc_AttributeError^,
3656- PyEngine.PyUnicodeFromString (Format(rs_ErrAttrGet,[KeyName, ErrMsg])));
3654+ PyEngine.PyErr_SetString (PyEngine.PyExc_AttributeError^,
3655+ PAnsiChar( PyEngine.EncodeString (Format(rs_ErrAttrGet,[KeyName, ErrMsg]) )));
36573656end ;
36583657
36593658function TPyDelphiObject.GetContainerAccess : TContainerAccess;
@@ -3816,9 +3815,9 @@ function TPyDelphiObject.Iter: PPyObject;
38163815 begin
38173816 Result := nil ;
38183817 with GetPythonEngine do
3819- PyErr_SetObject( PyExc_SystemError^,
3820- PyUnicodeFromString (Format(rs_ErrIterSupport,
3821- [Self.ClassName])) );
3818+ PyErr_SetString( PyExc_SystemError^,
3819+ PAnsiChar(EncodeString (Format(rs_ErrIterSupport,
3820+ [Self.ClassName]))) );
38223821 end ;
38233822end ;
38243823
@@ -3958,8 +3957,8 @@ function TPyDelphiObject.SetAttrO(key, value: PPyObject): Integer;
39583957 // If DelphiObject is nil exit immediately with an error
39593958 if not Assigned(DelphiObject) then
39603959 begin
3961- PyEngine.PyErr_SetObject (PyEngine.PyExc_AttributeError^,
3962- PyEngine.PyUnicodeFromString (rs_ErrObjectDestroyed));
3960+ PyEngine.PyErr_SetString (PyEngine.PyExc_AttributeError^,
3961+ PAnsiChar( PyEngine.EncodeString (rs_ErrObjectDestroyed) ));
39633962 Exit;
39643963 end ;
39653964
@@ -4528,7 +4527,7 @@ function TPyDelphiObject.MpAssSubscript(obj1, obj2: PPyObject) : Integer;
45284527 if not Prop.IsWritable then
45294528 begin
45304529 with Engine do
4531- PyErr_SetObject (PyExc_TypeError^, PyUnicodeFromString( rs_NotWritable));
4530+ PyErr_SetString (PyExc_TypeError^, PAnsiChar(EncodeString( rs_NotWritable) ));
45324531 Exit;
45334532 end ;
45344533
@@ -4595,8 +4594,8 @@ function TPyDelphiObject.SqAssItem(idx: NativeInt; obj: PPyObject): integer;
45954594 begin
45964595 Result := -1 ;
45974596 with GetPythonEngine do
4598- PyErr_SetObject ( PyExc_SystemError^,
4599- PyUnicodeFromString( Format(rs_ErrSqAss, [Self.ClassName])) );
4597+ PyErr_SetString ( PyExc_SystemError^,
4598+ PAnsiChar(EncodeString( Format(rs_ErrSqAss, [Self.ClassName]))) );
46004599 end ;
46014600end ;
46024601
@@ -4626,8 +4625,8 @@ function TPyDelphiObject.SqItem(idx: NativeInt): PPyObject;
46264625 begin
46274626 Result := nil ;
46284627 with GetPythonEngine do
4629- PyErr_SetObject( PyExc_SystemError^,
4630- PyUnicodeFromString( Format(rs_ErrSequence, [Self.ClassName])) );
4628+ PyErr_SetString( PyExc_SystemError^,
4629+ PAnsiChar(EncodeString( Format(rs_ErrSequence, [Self.ClassName]))) );
46314630 end ;
46324631end ;
46334632
@@ -4658,8 +4657,8 @@ function TPyDelphiObject.ToList_Wrapper(args: PPyObject): PPyObject;
46584657 begin
46594658 Result := nil ;
46604659 with GetPythonEngine do
4661- PyErr_SetObject( PyExc_SystemError^,
4662- PyUnicodeFromString( Format(rs_ErrSequence, [Self.ClassName])) );
4660+ PyErr_SetString( PyExc_SystemError^,
4661+ PAnsiChar(EncodeString( Format(rs_ErrSequence, [Self.ClassName]))) );
46634662 end
46644663 else if GetPythonEngine.PyArg_ParseTuple( args, ' :ToList' ) <> 0 then
46654664 with GetPythonEngine do
@@ -4682,8 +4681,8 @@ function TPyDelphiObject.ToTuple_Wrapper(args: PPyObject): PPyObject;
46824681 begin
46834682 Result := nil ;
46844683 with GetPythonEngine do
4685- PyErr_SetObject ( PyExc_SystemError^,
4686- PyUnicodeFromString( Format(rs_ErrSequence, [Self.ClassName])) );
4684+ PyErr_SetString ( PyExc_SystemError^,
4685+ PAnsiChar(EncodeString( Format(rs_ErrSequence, [Self.ClassName]))) );
46874686 end
46884687 else if GetPythonEngine.PyArg_ParseTuple( args, ' :ToTuple' ) <> 0 then
46894688 with GetPythonEngine do
@@ -4749,9 +4748,9 @@ function TPyDelphiMethodObject.Call(ob1, ob2: PPyObject): PPyObject;
47494748 on E: Exception do
47504749 begin
47514750 Result := nil ;
4752- PyErr_SetObject (PyExc_TypeError^,
4753- PyUnicodeFromString (Format(rs_ErrInvalidArgs,
4754- [MethodInfo.Name , E.Message])));
4751+ PyErr_SetString (PyExc_TypeError^,
4752+ PAnsiChar(EncodeString (Format(rs_ErrInvalidArgs,
4753+ [MethodInfo.Name , E.Message])))) ;
47554754 end ;
47564755 end ;
47574756end ;
@@ -5227,9 +5226,8 @@ function TPyDelphiWrapper.CreateComponent(pself, args: PPyObject): PPyObject;
52275226 Klass := nil ;
52285227 end ;
52295228 if (Klass = nil ) or not Klass.InheritsFrom(TComponent) then begin
5230- PyErr_SetObject(PyExc_TypeError^, PyUnicodeFromString(
5231- Format(rs_ErrInvalidArgs,
5232- [' CreateComponent' , rs_InvalidClass])));
5229+ PyErr_SetString(PyExc_TypeError^, PAnsiChar(EncodeString(
5230+ Format(rs_ErrInvalidArgs, [' CreateComponent' , rs_InvalidClass]))));
52335231 Exit;
52345232 end ;
52355233
@@ -5244,9 +5242,8 @@ function TPyDelphiWrapper.CreateComponent(pself, args: PPyObject): PPyObject;
52445242 Ownership := soOwned;
52455243 Result := Self.Wrap(Component, Ownership);
52465244 end else
5247- PyErr_SetObject(PyExc_TypeError^, PyUnicodeFromString(
5248- Format(rs_ErrInvalidArgs,
5249- [' CreateComponent' , ' ' ])));
5245+ PyErr_SetString(PyExc_TypeError^, PAnsiChar(EncodeString(
5246+ Format(rs_ErrInvalidArgs, [' CreateComponent' , ' ' ]))));
52505247 end ;
52515248end ;
52525249
0 commit comments