Get a handler from a script

Mark Smith mark at maseurope.net
Sun Mar 19 08:35:43 EST 2006


This might be dealt with better with a 'try...catch' structure. I  
don't know much about the error numbers that Rev produces, but

try
   cmdName
catch tError
   put tError
end try

where I know handler cmdName is commented out consistently produces  
this error string:
573,3,1,cmdName

This may or may not be useful in the context you described, but  
perhaps offers another way of testing for the existence or  
availability of a handler.


Mark


On 19 Mar 2006, at 13:18, David Burgun wrote:

> 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
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list