@@ -731,7 +731,8 @@ TPyDelphiListView = class(TPyDelphiCustomListView)
731731
732732 function CustomDrawTargetToPython (const ACustomDrawTarget: TCustomDrawTarget): PPyObject;
733733 function CustomDrawStageToPython (const ACustomDrawStage: TCustomDrawStage): PPyObject;
734- function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState): PPyObject;
734+ function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState;
735+ DelphiWrapper: TPyDelphiWrapper): PPyObject;
735736
736737 function ItemChangeToPython (const AItemChange: TItemChange): PPyObject;
737738 function ItemStateToPython (const AItemState: TItemState): PPyObject;
@@ -742,8 +743,10 @@ TPyDelphiListView = class(TPyDelphiCustomListView)
742743implementation
743744
744745uses
745- WrapDelphiTypes, WrapDelphiWindows,
746- Vcl.ExtCtrls;
746+ System.Rtti,
747+ Vcl.ExtCtrls,
748+ WrapDelphiTypes,
749+ WrapDelphiWindows;
747750
748751{ Register the wrappers, the globals and the constants }
749752type
@@ -780,31 +783,14 @@ function CustomDrawStageToPython(const ACustomDrawStage: TCustomDrawStage): PPyO
780783 Ord(ACustomDrawStage)));
781784end ;
782785
783- function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState): PPyObject;
784-
785- procedure Append (const AList: PPyObject; const AString: string);
786- var
787- LItem: PPyObject;
788- begin
789- with GetPythonEngine do begin
790- LItem := PyUnicodeFromString(AString);
791- PyList_Append(AList, LItem);
792- Py_XDecRef(LItem);
793- end ;
794- end ;
795-
786+ function CustomDrawStateToPython (const ACustomDrawState: TCustomDrawState;
787+ DelphiWrapper: TPyDelphiWrapper): PPyObject;
796788var
797- LCompType: PTypeInfo;
798- LMin: integer;
799- LMax: integer;
800- LState: integer;
789+ ErrMsg: string;
790+ Value : TValue;
801791begin
802- Result := GetPythonEngine().PyList_New(0 );
803- LCompType := GetTypeData(TypeInfo(TCustomDrawState)).CompType^;
804- LMin := LCompType^.TypeData^.MinValue;
805- LMax := LCompType^.TypeData^.MaxValue;
806- for LState := LMin to LMax do
807- Append(Result, GetEnumName(LCompType, LState));
792+ Value := TValue.From(ACustomDrawState);
793+ Result := TValueToPyObject(Value , DelphiWrapper, ErrMsg);
808794end ;
809795
810796function ItemChangeToPython (const AItemChange: TItemChange): PPyObject;
@@ -2203,7 +2189,7 @@ procedure TTVCustomDrawItemEventHandler.DoEvent(Sender: TCustomTreeView;
22032189 LPyTuple := PyTuple_New(4 );
22042190 PyTuple_SetItem(LPyTuple, 0 , LPyObject);
22052191 PyTuple_SetItem(LPyTuple, 1 , LPyNode);
2206- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
2192+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
22072193 PyTuple_SetItem(LPyTuple, 3 , LPyDefaultDraw);
22082194 try
22092195 LPyResult := PyObject_CallObject(Callable, LPyTuple);
@@ -2306,7 +2292,7 @@ procedure TTVAdvancedCustomDrawItemEventHandler.DoEvent(Sender: TCustomTreeView;
23062292 LPyTuple := PyTuple_New(6 );
23072293 PyTuple_SetItem(LPyTuple, 0 , LPyObject);
23082294 PyTuple_SetItem(LPyTuple, 1 , LPyNode);
2309- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
2295+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
23102296 PyTuple_SetItem(LPyTuple, 3 , CustomDrawStageToPython(Stage));
23112297 PyTuple_SetItem(LPyTuple, 4 , LPyPaintImages);
23122298 PyTuple_SetItem(LPyTuple, 5 , LPyDefaultDraw);
@@ -3098,7 +3084,7 @@ procedure TLVCustomDrawItemEventHandler.DoEvent(Sender: TCustomListView;
30983084 LPyTuple := PyTuple_New(4 );
30993085 PyTuple_SetItem(LPyTuple, 0 , LPyObject);
31003086 PyTuple_SetItem(LPyTuple, 1 , LPyItem);
3101- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
3087+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
31023088 PyTuple_SetItem(LPyTuple, 3 , LPyDefaultDraw);
31033089 try
31043090 LPyResult := PyObject_CallObject(Callable, LPyTuple);
@@ -3150,7 +3136,7 @@ procedure TLVCustomDrawSubItemEventHandler.DoEvent(Sender: TCustomListView;
31503136 PyTuple_SetItem(LPyTuple, 0 , LPyObject);
31513137 PyTuple_SetItem(LPyTuple, 1 , LPyItem);
31523138 PyTuple_SetItem(LPyTuple, 2 , PyLong_FromLong(SubItem));
3153- PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State));
3139+ PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State, PyDelphiWrapper ));
31543140 PyTuple_SetItem(LPyTuple, 4 , LPyDefaultDraw);
31553141 try
31563142 LPyResult := PyObject_CallObject(Callable, LPyTuple);
@@ -3251,7 +3237,7 @@ procedure TLVAdvancedCustomDrawItemEventHandler.DoEvent(Sender: TCustomListView;
32513237 LPyTuple := PyTuple_New(5 );
32523238 PyTuple_SetItem(LPyTuple, 0 , LPyObject);
32533239 PyTuple_SetItem(LPyTuple, 1 , LPyItem);
3254- PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State));
3240+ PyTuple_SetItem(LPyTuple, 2 , CustomDrawStateToPython(State, PyDelphiWrapper ));
32553241 PyTuple_SetItem(LPyTuple, 3 , CustomDrawStageToPython(Stage));
32563242 PyTuple_SetItem(LPyTuple, 4 , LPyDefaultDraw);
32573243 try
@@ -3304,7 +3290,7 @@ procedure TLVAdvancedCustomDrawSubItemEventHandler.DoEvent(
33043290 PyTuple_SetItem(LPyTuple, 0 , LPyObject);
33053291 PyTuple_SetItem(LPyTuple, 1 , LPyItem);
33063292 PyTuple_SetItem(LPyTuple, 2 , PyLong_FromLong(SubItem));
3307- PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State));
3293+ PyTuple_SetItem(LPyTuple, 3 , CustomDrawStateToPython(State, PyDelphiWrapper ));
33083294 PyTuple_SetItem(LPyTuple, 4 , CustomDrawStageToPython(Stage));
33093295 PyTuple_SetItem(LPyTuple, 5 , LPyDefaultDraw);
33103296 try
0 commit comments