the formattedText of

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

the formattedText of

Post by ukimiku » Thu Oct 22, 2009 10:52 am

Dear Runtime users,

I have worked through the "Working with text" tutorial. When it comes to inserting text, the following code snipped is provided:

on mouseUp
repeat with i = 1 to the number of lines in field "sample text"
put "Some text. " before line i of field "sample text"
end repeat
end mouseUp

Now I would like to insert "some text" before each line as it is printed in the screen. Since I just learned that, when I want to address the lines of text as they are formatted on the screen, I use "the formattedText of", and so I changed the above script to:

on mouseUp
repeat with i = 1 to the number of lines in field "sample text"
put "Some text. " before line i of the formattedText of field "sample text"
end repeat
end mouseUp

But this gives an error, not specifying what I did or thought wrong.

Could anyone provide an insight, please? Thanks.

Regards

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Oct 22, 2009 12:30 pm

Dear palindrome
(ukimiku reads forwards and backwards the same)

Welcome to the forum.

Think of the formattedText as an internal representation of the text of a field. The same as the HTMLtext of a field.
As you say it contains the linebreaks as they are displayed on screen and not the linebreaks of the text.
You can extract the formattedText and work on it as you did:

Code: Select all

on mouseUp 
   put the formattedText of field "sample text" into myTextToWorkOn
   repeat with i = 1 to the number of lines in myTextToWorkOn
      put i & " " before line i of myTextToWorkOn
   end repeat 
   put myTextToWorkOn into field "sample text"
end mouseUp 
it takes the formattedText and prepends a line number and puts it back into the field. Not surprisingly the lines run over the width of the field and now the the formattedText would be different again.

You can also "say put the formattedText of field "xyz" into field "xyz""
Now the appearence of the field does not change but the linebreaks are different from before.

You might also want to look at the htmlText of a field. I use it more often then the formattedtText.
regards
Bernd

ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

the formattedText of

Post by ukimiku » Thu Oct 22, 2009 2:25 pm

Hi Bernd,

thanks for your alternative way of achieving the insertions. I understand your approach, but still do not understand why mine throws an error. I am new to Runtime, and I am trying to build a mental model of how the language concept is constructed. I know AppleScript and RealBasic, so I am familiar with both the "natural" language and object models, but it beats me why I can't change formattedText as it seems so natural and logical an approach. I really could use some enlightenment on the underlying mode: why can I change the lines of a text field by inserting but not the lines as they appear on the screen?

Again, thanks for replying, and special thanks for not doing it palindromatically!

Regards, :)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Oct 22, 2009 2:44 pm

Hi ukimiku,

I think it throws an error because you access a property (as opposed to a container) with a chunk operation. I think you can not do that and have to take the property first, put it into a container (variable in this case) and do your chunk operation (put xxx before line y of container) and set the property wholesale to the container.
But there are more experienced experts around that might have a say on this.
regards
Bernd

ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

the formattedText of

Post by ukimiku » Thu Oct 22, 2009 3:17 pm

Hi Bernd,

thanks for explaining. Now I have a working understanding of the issue and will move on to getting to know the language better.

Regards,

Post Reply