Page 1 of 1

Problem calling a command

Posted: Fri Feb 19, 2010 3:34 am
by phaworth
I have the following snippet of code:

Code: Select all

send "menuPick " & the label of button "GigsFilterMenu" to button "GigsFilterMenu"
     highlightLineByKey myKey,1,group "GigList"
The handler containing this code works fine until it reaches the call to highlightLineByKey. I have a break point at the first line of highlightLineByKey and it never reaches that breakpoint. I can tell that the send command is working fine and the object it responds to does what it's supposed to do.

Here's the code for the highlightLineByKey:

Code: Select all

command highlightLineByKey pKey,pColumn,pList
   /* 
   Finds a value in a column of a datagrid and scrolls to the line containing it
   Parameters are:
   - pKey: the key value to be found
   -pColumn: the number of the column to be searched
   -pList: the short name of the datagrid to be searched
   */
   put 1 into myLine
   set the itemdelimiter to tab
   repeat with count=1 to the dgNumberOfLines of pList
      if item pColumn of line count of the dgText of pList = pKey then 
         put count into myLine
         exit repeat
      end if
   end repeat
   set the dgHilitedLine of pList to myLine
end highlightLineByKey
If I cut and paste that code line-for line (except for replacing the parameters with real names/etc) into the higher level handler,it works fine.

Only other thing I can think of is that the highlight routine is in a front script but there's plenty of other commands and functions in there and they are working fine.

Any ideas?

Pete

Re: Problem calling a command

Posted: Fri Feb 19, 2010 1:00 pm
by bn
Pete,
I get an error with the parameters you posted, it works if I put

Code: Select all

 highlightLineByKey myKey,1,"GigList" -- this is the short name of the group
than in the the command highlightLineByKey

Code: Select all

   put 1 into myLine
   set the itemdelimiter to tab
   repeat with count=1 to the dgNumberOfLines of group pList
      if item pColumn of line count of the dgText of group pList = pKey then 
         put count into myLine
         exit repeat
      end if
   end repeat
   set the dgHilitedLine of group pList to myLine
could you try this?

looking at your code you access the dgText of group xyz very often in your repeat loop, wouldn' t it be faster to load the dgText into a local variable and then do your matching test on that?
something like this:

Code: Select all

   put 1 into myLine
   set the itemdelimiter to tab
   put  the dgText of group pList into myDgText -- get dgText only once
   put 0 into tCount
      repeat for each line aLine in myDgText
         add 1 to tCount
         if item pColumn of aLine = pKey then 
            put tcCount into myLine
            exit repeat
         end if
      end repeat
      set the dgHilitedLine of group pList to myLine

regards
Bernd

Re: Problem calling a command

Posted: Fri Feb 19, 2010 6:07 pm
by phaworth
Thanks Bernd, sounds like you found the problem. The strange thing is I didn't get any sort of error, either during compile or at run time, but I can see that what I did would cause a problem.

Thanks also for the tip on putting dgText into a local variable. I'll do that. In fact what I really want to do is use the FindLine command provided by the datagrid library but I can't get that to work for me, always returns zero as the line number.

Pete