Observer.Detach() is a new method that disconnects the observer from the observed object.

[INTERPRETER]
* NEW: Observer.Detach() is a new method that disconnects the observer from the observed object.
This commit is contained in:
gambas 2022-02-01 02:05:19 +01:00
parent 2a90e5f081
commit 691144bba9

View file

@ -132,6 +132,20 @@ BEGIN_PROPERTY(Observer_Tag)
END_PROPERTY
BEGIN_METHOD_VOID(Observer_Detach)
OBJECT_EVENT *ev;
if (!THIS->object)
return;
ev = OBJECT_event(THIS->object);
LIST_remove((void **)&ev->observer, THIS, &THIS->list);
THIS->object = NULL;
OBJECT_UNREF(_object);
END_METHOD
#endif
GB_DESC NATIVE_Observer[] =
@ -144,5 +158,7 @@ GB_DESC NATIVE_Observer[] =
GB_PROPERTY_READ("Object", "o", Observer_Object),
GB_PROPERTY("Tag", "v", Observer_Tag),
GB_METHOD("Detach", NULL, Observer_Detach, NULL),
GB_END_DECLARE
};