[squeak-dev] Execute code when a Morph is destroyed

Igor Stasenko siguctua at gmail.com
Tue Jan 6 20:37:33 UTC 2009


2009/1/6 Séverin Lemaignan <skadge at gmail.com>:
> Thanks for your very quick reply!
>
> As I understand it, the "finalize" method is called only upon object
> destruction. But if the object is only dropped to the bin, it's not
> destroyed, is it?

I never dealt with bin in Morphic.
But something tells me that you employing wrong model :)
In a right way, you should use a separate class which operates with
com port, and morph should be a view of an instance of such object.
Then your question will lose context, since you have a model - which
acts by itself and closing external resources when it becomes garbage.
And you have a morph, which is a view of your model object, and you
can have as many views as you want to, and it is irrelevant if any of
them alive or not, putted in bin or somewhere else :)

>
> Anyway, finalization is already helpful!
>
> Bye,
> Séverin
>
>
> On Tue, Jan 6, 2009 at 20:48, Igor Stasenko <siguctua at gmail.com> wrote:
>> 2009/1/6 Séverin Lemaignan <skadge at gmail.com>:
>>> Hello,
>>>
>>> I would like to execute some code (closing a serial port) when a morph
>>> is destroyed by an user (either by clicking on the cross or by
>>> drag&dropping the morph to the bin). Do you know how to do that?
>>>
>> Use finalization for closing any external resources being used by
>> squeak-based objects.
>> Example:
>>
>> WeakRegistry default add: myObject.
>>
>> MyClass>>finalize
>>   self closeAllPorts.
>>
>>> As a bonus question, is it possible to detect, on the contrary, when a
>>> morph is restored from the bin (to reestablish the communication) ?
>>>
>> Don't know about morph-specifics too much.
>>
>>> Thank you!
>>> Séverin
>>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>>
>>
>>
>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Squeak-dev mailing list