Get a handler from a script

David Burgun dburgun at dsl.pipex.com
Sun Mar 19 08:18:27 EST 2006


Hi,

The problem is that if you are doing something like this:

if the script of myObject contains "on HandlerName" then
   send HandlerName to myObject
end if

This this will work if the Hander is NOT commented out, but will fail  
with an error if the handler IS commented out. Also if you have a  
comment in a Script that just happens to contain "on HandlerName"  
then the "if" will succeed even though there is no handler defined.

I had a problem that took me ages to figure out. In a script I had  
something like the following:

--on Update make sure the field is not selected

which meant that:

if the script of myObject contains "on Update" then

succeeded, but the send statement failed since there wasn't really a  
handler called "update" defined. Checking for "end Update" *may* have  
worked, as long as there was not a line that read something like:

send Update to myObject

Also checking for "end Update" slows the whole process down.

What would be nice is the ability to check if a (real) handler exists  
not just that the script contains text that looks like a handler  
defintion. Something like this would be good:

if exists(handler "Update" in script of myObject) then

Which would make it 100% foolproof.

All the Best
Dave

On 17 Mar 2006, at 12:19, Mark Smith wrote:

> Commenting would only affect things if the wholeMatches is set to  
> true - normally, lineOffset will get the right line even if it's  
> commented out, no?
>
> Mark
>
> On 17 Mar 2006, at 12:06, David Burgun wrote:
>
>> Hi,
>>
>> Of course none of the solutions so far work if the function is  
>> commented out. To make the code 100% foolproof is a lot of work. I  
>> was doing something similar and found that comments made life  
>> really difficult.
>>
>> All the Best
>> Dave
>>
>> On 17 Mar 2006, at 11:42, Robert Brenstein wrote:
>>
>>>> Perhaps using
>>>>
>>>> set the wholematches to true
>>>> put lineOffset("on" && pHandlerName, pScript) into tStart
>>>> if tStart is 0 then put lineOffset("function" && pHandlerName,  
>>>> pScript) into
>>>> tStart
>>>> put (lineOffset("end" && pHandlerName, pScript) +1 into tEnd
>>>>
>>>>
>>>> answer tStart & cr & tEnd
>>>>
>>>> Jim Ault
>>>> Las Vegas
>>>>
>>>
>>> Unfortunately, wholematches can't be used, at least for the first  
>>> lineoffset, because there are likely some parameters further in  
>>> that line. The alternative to lineOffset is to use regex.
>>>
>>> A truly generic function would need to know whether it searches  
>>> for command or function, because it is possible to have one of  
>>> each with the same name.
>>>
>>> Robert




More information about the use-livecode mailing list