Re: How do you check the equivalency of references?
Re: How do you check the equivalency of references?
- Subject: Re: How do you check the equivalency of references?
- From: Nigel Garvey <email@hidden>
- Date: Sat, 11 Aug 2001 11:46:46 +0100
Nigel Garvey wrote on Sat, 11 Aug 2001 01:37:16 +0100:
>
John W Baxter wrote on Fri, 10 Aug 2001 15:49:48 -0700:
>
>
>At 17:52 -0400 8/10/2001, Arthur J Knapp wrote:
>
>>> Subject: Re: How do you check the equivalency of references?
>
>>> Date: Fri, 10 Aug 2001 14:29:38 +0100
>
>>> From: Nigel Garvey <email@hidden>
>
>>
>
>>> on isRef(val)
>
>>> try
>
>>> contents of val
>
>>> return (result is not val)
>
>>> on error
>
>>> return false
>
>>> end try
>
>>> end isRef
>
>>
>
>> There is another way to determine references:
>
>>
>
>> count of references in {v} = 1
>
>
Looks good!
>
>
>> Richard 23 once pointed out to me a very good reason why the
>
>>"contents of" method is better, though I can't recall what it was.
>
>
I'll have to try a few things tomorrow morning. Maybe someone in a
>
different time zone will discover the reason before then. One difference
>
between the methods is that my handler returns 'false' for a Finder
>
reference whereas the list method returns 'true'. Which is better depends
>
on what you want, I suppose.
It turns out to be the same with Claris Emailer. It seems that the
contents of an application reference is often the reference itself. This
fools my handler into thinking that it's not a reference at all.
tell application "Claris Emailer"
set r to deleted mail folder
--> folder id 4 of application "Claris Emailer"
set c to contents of r
--> folder id 4 of application "Claris Emailer"
end tell
tell application "Finder"
set r to folder "Internet" of startup disk
--> folder "Internet" of startup disk of application "Finder"
set c to contents of r
--> folder "Internet" of startup disk of application "Finder"
end tell
The values of c are the same whether they're tested inside the 'tell'
block or outside it - unless the referenced application object has a
'contents' property:
tell application "JPEGView"
set r to front window
set c to contents of r
--> image
end tell
set c to contents of r
--> window 1 of application "JPEGView"
... which of course makes no difference if c is tested by an external
handler. The contents of the reference is still the reference itself.
My conclusion is that Arthur's method is a far more reliable test of
"referencehood".
(count {r}'s references) = 1
NG