Re: Newbie Question: Script Objects
Re: Newbie Question: Script Objects
- Subject: Re: Newbie Question: Script Objects
- From: Simon Brown <email@hidden>
- Date: Mon, 17 Feb 2003 20:28:29 +0000
Martin Crisp <email@hidden> wrote:
>
Properties are inherent to the script - if they change the change
>
'sticks' (provided the script completes) until it is recompiled.
Please see my earlier post in reply to Andrew Oliver (Mon, 17 Feb 2003
00:22:52 +0000) with example showing that properties of Script Objects (as
opposed to scripts) DO reset every time the script is closed and reopened -
or do you mean the script is recompiled every time it is opened, even if no
changes are made?
You also wrote:
>
tell my myHandlers to increment()
(* addition of the 'my' pronoun makes it work *)
Which does indeed work, regardless of the position of the script object in
the script. I should just be happy that it does, but it seems to contradict
John Baxter's response, the logic of which I had just convinced myself:
>
It's fairly easy to look ahead lexically for a variable...once xxx has
>
become the name of a variable, it remains the name of that variable.
>
>
However, once a variable yyy contains a script object, it doesn't
>
necessarily remain a script object.
>
This is, roughly, the minimal example in which it doesn't remain a script
>
object:
>
>
script yyy
>
end script
>
>
set yyy to 5
>
>
display dialog yyy
>
--(displays 5)
Thinking about it, no matter where the script object is defined, Applescript
must scan the entire script (or at least up to the last call to the script
object) to see that the variable assigned to the script object is not
redefined anywhere as an integer/string etc when it compiles... I guess???
Another complication I've thought of is that I hadn't really considered the
implications of script object names being variables. As a variable without a
'global' declaration it should NOT be available to any handlers except for
the run handler if declared at the root level of the script. It seems
strange that the language actually allows the reassignment of the name of a
defined object (its identifier) to a 'general' variable as in John's example
above. i.e. set run to 5 or set run to "anystring" doesn't work.
To summarise WHY I want to use a script object (for handling time-range
calculations):
1) I want to reuse it in a variety of scripts without having to add globals
or properties at the root level of the scripts that only apply to the script
object. This is part of my modular design philosophy.
2) I want the properties of the script object to be reset every time the
script apps containing or loading it are launched & run but to persist
outside the duration of calls to the handlers in the script object itself
(as one or more of the routines within it may be called many times during
the execution of stay-open script apps).
3) Eventually, I'll need a Smile (or Dialog Director) dialog for setting
ranges and changing settings, though at present I'm only using AS dialogs.
As it all adds up to a lot of code I'd like to be able to separate it neatly
from script apps that use it.
Hope that makes some kind of sense. I've created classes in Visual Basic to
perform similar functions, but if my programming strategy is way off please
let me know. Alternatively, if I'm reinventing the wheel and someone has
already done a neat job of this or written an OSAX, I'd love to see it.
I feel that I'm making good progress with AS at the moment, almost entirely
thanks to members of this group. Thanks to everyone who's helped me thus far
:))
-------------
Simon Brown
-------------
PPC 7500 + G3 card/OS z9.1 + Remote Access 4.02/AppleScript 1.8.3/Smile
1.8.8
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.