On or about 7/16/07 12:18 PM, thus spake "Christiaan Hofman"
<email@hidden>:
>
> On 16 Jul 2007, at 9:08 PM, Matt Neuburg wrote:
>
>> On Fri, 13 Jul 2007 15:12:47 -0500, Scott Thompson <email@hidden>
>> said:
>>> I'm working on an AppleScript class for my application and I'd
>>> like to
>>> create some properties that can be defined when an instance of the
>>> class is created, but which are read-only afterward.
>>>
>>> For example, the instances of the class include the "name" and
>>> "category" properties. These properties are defined when the
>>> instance
>>> is created, and can be read afterward, but there should not be any
>>> way
>>> to change those properties.
>>>
>>> I'm curious about the right way to express that in the sdef and in
>>> the
>>> running application. I envision two scenarios:
>>>
>>> 1. I mark the properties as "read-only" in the sdef and require the
>>> user to specify the value of those properties in the "with
>>> properties"
>>> parameter of the "make" command. Can a read-only property still be
>>> initialized with the "with properties" parameter?
>>>
>>> 2. I leave the properties read/write but just return an error if you
>>> try to set the value after the instance is created.
>>>
>>> Is either of these scenarios the preferred one?
>>
>> I don't know if there's a general policy, but I lean towards #2. I
>> would
>> provide a really informative error message if the user tries to
>> change one
>> of these properties after creation, and also be verbosely
>> informative in the
>> dictionary (now that sdefs allow us to be so).
>>
>> m.
>
> I don't think 2 works (as in my earlier post on this thread).
> NSCreateCommand sets all properties from the "with properties"
> arguments after initializing the object, so it calls those setters.
> Therefore returning an error in the setters will actually return the
> error from the 'make' command , which was precisely what the OP tried
> to accomplish
Well, but you also have to think. I mean, your code has to decide whether
it's being called because there's a creation going on or because the user is
trying to change the property of an already existing object. It is possible
to tell the difference. m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
AppleScript: the Definitive Guide - Second Edition!
http://www.amazon.com/gp/product/0596102119
Take Control of Word 2004, Tiger, and more -
http://www.takecontrolbooks.com/tiger-customizing.html
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/email@hidden
This email sent to email@hidden