www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@containerData/connectData.m

    function connectData(obj, data)
%CONNECTDATA Connect new data to existence of object
%
%  CONNECTDATA(OBJ, DATA) adds a new piece of data that should be explicitly
%  destroyed when the object is destroyed.

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.


if isempty(obj.destructionlistener)
    L = handle.listener(obj, 'ObjectBeingDestroyed', {@i_deletedata, {data}});
    obj.destructionlistener = L;
else
    CB = obj.destructionlistener.Callback;
    CB{2} = [CB{2}, {data}];
    obj.destructionlistener.Callback = CB;
end


function i_deletedata(src, evt, data)
if ~mbcgui.util.isBeingDestroyed(src.Parent)
    for n = 1:length(data)
        if mbcgui.util.isComponentHandle(data{n})
            delete(data{n});
        end
    end
end