Deleting a line in a scrolling list field

Ken Ray kray at sonsothunder.com
Tue Nov 21 10:23:37 EST 2006


On 11/21/06 6:03 AM, "Scott Kane" <scott at cdroo.com> wrote:

> Hi Eric,
> 
>> You can use a simple "delete line x of field y" but...
>> When you say you could probably load the list into into a variable
>> and then parse it back to the list field, you are completely right.
>> This way of doing is much faster.
>> Always prefer to parse a variable than acting directly on any
>> displayed contents.
> 
> Thanks a bunch as always.  Working nicely.  :-)

Just one additional comment... if you have multiple lines you need to
delete, I would recommend working from the bottom to the top (i.e. reverse
order) instead of top to bottom, otherwise you'll delete the wrong lines.

For example, if you need to delete lines 1 and 3 from this list:

Apples
Oranges
Bananas
Grapes
Peaches

You want to end up with (of course):

Oranges
Grapes
Peaches

But if you delete them in order (delete line 1 then delete line 3), you'll
end up with this:

Oranges
Bananas
Peaches

because after you've deleted line 1, the container is different and line 3
of the container is now Grapes instead of Bananas. You could make an
adjustment each time through the loop (delete line 1, then delete line
(3-1)), but I prefer to work backwards instead (delete line 3 then line 1).

So suppose you had this list in a list field and lines 1 and 3 were
highlighted. You could use either of the following to delete the items:

-- Forward, with adjustment
on mouseUp
  put the hilitedLines of me into hLines
  put me into tData  -- operate on the variable instead of the field
  repeat with x = 1 to the number of items of hLines
    delete line ((item x of hLines) - (x-1)) of tData
  end repeat
  put tData into me
end mouseUp

OR

-- Backwards
on mouseUp
  put the hilitedLines of me into hLines
  put me into tData  -- operate on the variable instead of the field
  repeat with x = the number of items of hLines down to 1
    delete line (item x of hLines) of tData
  end repeat
  put tData into me
end mouseUp

You probably already know this stuff, but it doesn't hurt to put it out
there for others who may be in the same situation...

HTH,

Ken Ray
Sons of Thunder Software, Inc.
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com





More information about the use-livecode mailing list