Skip to content

Commit 8c80e5d

Browse files
committed
Fix #93
1 parent 3d7515d commit 8c80e5d

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

PythonForDelphi/Components/Sources/Core/WrapDelphiClasses.pas

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -791,18 +791,22 @@ function TPyDelphiComponent.BindMethodsToEvents(args: PPyObject): PPyObject;
791791
if Assigned(_comp) and Assigned(objComp) and IsPublishedProp(_comp, _eventName) then
792792
begin
793793
objMethod := PyObject_GenericGetAttr(GetSelf, key);
794-
if PyErr_Occurred <> nil then
795-
Exit;
796-
PyObject_SetAttrString(objComp, PAnsiChar(AnsiString(_eventName)), objMethod);
797-
if PyErr_Occurred <> nil then
798-
Exit
799-
else
800-
begin
801-
_pair := PyTuple_New(3);
802-
PyTuple_SetItem(_pair, 0, PyString_FromDelphiString(_compName));
803-
PyTuple_SetItem(_pair, 1, PyString_FromDelphiString(_eventName));
804-
PyTuple_SetItem(_pair, 2, objMethod);
805-
PyList_Append(_bindings, _pair);
794+
try
795+
if PyErr_Occurred <> nil then
796+
Exit;
797+
PyObject_SetAttrString(objComp, PAnsiChar(AnsiString(_eventName)), objMethod);
798+
if PyErr_Occurred <> nil then
799+
Exit
800+
else
801+
begin
802+
_pair := PyTuple_New(3);
803+
PyTuple_SetItem(_pair, 0, PyString_FromDelphiString(_compName));
804+
PyTuple_SetItem(_pair, 1, PyString_FromDelphiString(_eventName));
805+
PyTuple_SetItem(_pair, 2, objMethod);
806+
PyList_Append(_bindings, _pair);
807+
end;
808+
finally
809+
Py_XDecRef(objMethod);
806810
end;
807811
end;
808812
end;

PythonForDelphi/Demos/Demo31/Unit1.dfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ object Form1: TForm1
104104

105105
' self.Caption = self.Caption + '#39' - changed by Python subclass' +
106106
#39
107-
' #self.BindMethodsToEvents()'
107+
' self.BindMethodsToEvents()'
108108
''
109109
' def handle_btnAdd_OnClick(self, Sender):'
110110
' self.ListBox1.Items.Add(self.Edit1.Text)'

0 commit comments

Comments
 (0)