Set the imagesource of a character to a built in graphic

J. Landman Gay jacque at hyperactivesw.com
Sat Jun 24 02:14:32 EDT 2017


On 6/23/17 6:48 PM, Bob Sneidar via use-livecode wrote:
> Okay so here is an odd thing. Given that the imageSource of char 1 of eack line of a scrolling field is set to a graphic (A plus sign in this case):
> 
> on selectionChanged
>     put the clickChar into tChar
>     if tText is not space then exit selectionChanged
> 
>     put word 2 of the clickLine into tLine
>     put the buttonlist of me into aButtonList -- an array
>     put aButtonList ["buttonNames"] into tButtonList -- contains names of 3 buttons each line preceded by 2 tabs
>     
>     if tButtonList is not in me then
>        put tButtonList before line tLine+1 of me -- works great!
>     else
>        replace tButtonList with empty in me -- removes the imageSource on char 1 of every line
>     end if
> end selectionChanged
> 
> 
> This works, but on the second click it replaces the imageSource on every line. That shouldn't happen should it??

ImageSource is sort of like text styles, you can see it most clearly in 
the htmlText of a field. An imageSource is represented by tags just like 
bold, italic, and other styles. You'd see the same behavior if the lines 
were bold instead of having an imageSource.

Inserting some lines into a field doesn't change the styling of the 
other lines, it just adds some additional unstyled text.

The replace command works only on plain text and in this case the script 
is passing the entire content of the field. The replace command gets the 
full text, does the replacement, and puts the text back. As far as it's 
concerned, the imageSource characters are just spaces. Styling tags are 
ignored and consequently stripped out.

You can either get the lineOffset of the unwanted lines and delete only 
those, which leaves the htmlText intact elsewhere, or you could get the 
htmlText of the field, do the replacement, and then set the field's 
htmlText to the revised content.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list