MagicListener

버전 1.0.0.0 (2.71 KB) 작성자: Benoit Charles
MagicListener object
다운로드 수: 450
업데이트 날짜: 2012/1/16

라이선스 보기

MagicListener constructor creates a listener just like the addlistener function. The difference is the constructor accepts one more input, one object or a cell of objects, and the life cycle of the returned object will be linked also on these objects.

Exemple:

Without MagicListener:

[Class1.m]
classdef Class1 < handle
events
myEvent
end
end

[Class2.m]
classdef Class2 < handle
methods
function this = Class2( obj1 )
addlistener( obj1, 'myEvent', @(H,E) this.callback() );
end
function callback( this )
disp( 'CALLBACK!' );
end
end
end

>> obj1 = Class1();
>> obj2 = Class2( obj1 );
>> notify( obj1, 'myEvent' );
CALLBACK!
>> delete( obj2 );
>> notify( obj1, 'myEvent' );
Warning: Error occurred while executing callback:
Invalid or deleted object.

With MagicListener:

[Class1.m]
classdef Class1 < handle
events
myEvent
end
end

[Class2.m]
classdef Class2 < handle
methods
function this = Class2( obj1 )
MagicListener( obj1, 'myEvent', @(H,E) this.callback(), this );
end
function callback( this )
disp( 'CALLBACK!' );
end
end
end

>> obj1 = Class1();
>> obj2 = Class2( obj1 );
>> notify( obj1, 'myEvent' );
CALLBACK!
>> delete( obj2 );
>> notify( obj1, 'myEvent' );

인용 양식

Benoit Charles (2024). MagicListener (https://www.mathworks.com/matlabcentral/fileexchange/34606-magiclistener), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2008b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Handle Classes에 대해 자세히 알아보기
태그 태그 추가
도움

줌: Graphical Wrappers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0