From: <HIDDEN>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webcrossing
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to add a new property to a handle?
Message-ID: <ef537ba.9@webcrossing.raydaftYaTP>
Date: Thu, 19 Apr 2007 15:54:36 -0400
References: <ef537ba.1@webcrossing.raydaftYaTP> <ev3nli$g8b$1@canopus.cc.umanitoba.ca> <ef537ba.3@webcrossing.raydaftYaTP> <ef537ba.4@webcrossing.raydaftYaTP> <ef537ba.5@webcrossing.raydaftYaTP>
Lines: 47
NNTP-Posting-Host: 80.178.76.226
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:404222



I was asked the following question by email,which I think is of
general interest so I post it here (with my answer):

    Hi Yair,

    You mentioned that you had found a way to add a new property
'MyProp' to a handle graphics object so that set or get(h,'MyProp')
would work.

    I tried to find out how from your UICOMPONENT code but I'm afraid
most of that Java interaction is over my head. If it's not too much
trouble, could you send me just the snippet of code that would
accomplish this? I'd really appreciate it.

And my answer:

Assume your handle is h, then:

sp = schema.prop(h, 'newPropName', 'mxArray');

% Usage examples
set(h, 'newPropName', magic(3)); % setting new property
get(h, 'newPropName'); % getting new property
get(h); % newPropName will NOT be shown
get(handle(h)); % newPropName WILL be shown
sp = findprop(handle(h),anyPropName); % get the property's
definition

% Special (optional) property processing
sp.DataType = 'bool'; % modify property data type (mxArray is
recommended in most cases)
sp.AccessFlags.PublicSet = 'off'; % make the new prop read-only
(default = 'on')
sp.AccessFlags.PublicGet = 'off'; % make the new prop write-only
(default = 'on')
sp.Visible = 'off'; % hide it from get(handle(h)) - you can still
get/set it, though (default = 'on')
sp.GetFunction = @myGetFunc; % set getter function (default = [])
% Note: func signature is: returnedPropValue = myGetFunc
(object,storedPropValue)
sp.SetFunction = {@mySetFunc,myParam1,myparam2}; % Same for setter
function with 2 optional args
% Note: func signature is: storedPropValue = mySetFunc
(object,proposedPropValue,arg1,arg2) - only first 2 args mandatory
get(sp); % to see everything else that's settable about this prop

Yair Altman