Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Update and Delete listeners

Subject: Update and Delete listeners

From: kees de Kapper

Date: 26 Jun, 2013 13:07:07

Message: 1 of 4

Hi All,

I've got a question about listeners. I'm trying to create an Image/Data Object. What I would like to implement is a listener when the object has changed (to call a separate function for updating) and a listener for deletion (to remove all dependencies outside the Object).
I have been looking for a simple tutorial but most of what I found was beyond my needs.

I would come up with something like this, but unfortunately it is not complete/won't work:
===================================================
classdef ImageObject < handle
    properties
        Data = [];
        Axis = [];
    end;
    events
        Delete
        Changed
    end;
    methods
        function obj = ImageObject(varargin)
            % some preparation/initialisation code
            addlistener(obj,'Delete', @ImageObject.DeleteHandler);
            addlistener(obj,'Changed',@ImageObject.ChangedHandler);
        end;
        function DeleteHandler(obj, eventData)
            % some code
        end;
        function ChangedHandler(obj, eventData)
            % some code
        end;
    end;
end;
===================================================

What do I have to modify to have my listeners (besides of telling better stories ;-)

Many thanks in advance!

Kees

Subject: Update and Delete listeners

From: kees de Kapper

Date: 28 Jun, 2013 14:29:10

Message: 2 of 4

Hi All,

I have been playing a little with events and listeners and came up with a usable implementation to update my object, etc.
However, what I would like to have as well, is a listener of the event that the object is (going to be) destroyed/deleted. I would like to have the possibility to clean up several dependencies just before deletion.

I cannot find some an event like 'Delete' or what so ever. Have I missed something.

Many thanks in advance.

Kind regards,
Kees

Subject: Update and Delete listeners

From: Steven_Lord

Date: 28 Jun, 2013 15:36:47

Message: 3 of 4



"kees de Kapper" <kees_de_kapper@hotmail.com> wrote in message
news:kqk6jm$on1$1@newscl01ah.mathworks.com...
> Hi All,
>
> I have been playing a little with events and listeners and came up with a
> usable implementation to update my object, etc. However, what I would like
> to have as well, is a listener of the event that the object is (going to
> be) destroyed/deleted. I would like to have the possibility to clean up
> several dependencies just before deletion.
>
> I cannot find some an event like 'Delete' or what so ever. Have I missed
> something.

Create a DELETE method for your object. Clean up the dependencies in that
method.

http://www.mathworks.com/help/matlab/matlab_oop/handle-class-destructors.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Update and Delete listeners

From: kees de Kapper

Date: 1 Jul, 2013 09:47:09

Message: 4 of 4

After being busy with listeners, I didn't thought that it was that easy. Thanks for the answer!

/Kees

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us