Page 1 of 1
Detecting change to FormattedText
Posted: Sun Oct 18, 2020 9:04 am
by kaveh1000
Hi folks
I have a field with a large volume of text. I am doing some moving around for which I need the current value of FormattedText, as I need to know where the soft line breaks are, and the number of lines after line breaking.
If the text itself changes, I can use
Code: Select all
on TextChanged
(update value of FormattedText)
end TextChanged
but the FormattedText can also change of the following are modified:
text size
field dimensions
field border
etc
I want to minimise the call to grab the FormattedText, so looking for something like
Code: Select all
on FormattedTextChanged
(update value of FormattedText)
end FormattedTextChanged
Any ideas on the best way to achieve this?
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 9:29 am
by FourthWorld
You'll need to update the routine that responds to formattedText changes in the UI you provide for altering the properties that will affect it.
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 9:42 am
by kaveh1000
Not sure I understand Richard. Let me describe the use case:
The user will be interacting with the field (with locked text) using the mouse and/or arrow keys. I need to know which line they clicked on, counting from the top in FormattedText, as well as the length of the lines. There is a lot of interaction, but the field content and size only changes occasionally.
I could check the formattedText at each mouse click and arrow key, but that is too much drain on the system. So I want to read the value of FormattedText only when the text is updated, or when the field is resized. I could use a series of handlers to check for size of field, text size, etc, but wondered if there is a more elegant way of updating the FormattedText value only when it changes.
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 10:17 am
by FourthWorld
If the field resizing is done with the pointer tool you can trap the resizeControl message.
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 6:31 pm
by jacque
Offhand I can't see a way to avoid checking on every arrow key or mouse click, but you can streamline things by looking at the properties of the field.
Save "the properties of fld x" in a script local and when interactions occur, compare the current properties to the stored one. This is very fast. If they're different, save the new properties in the local variable and do whatever you need with the new configuration.
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 6:38 pm
by kaveh1000
Thank you Jacqueline. This is excellent. I had no idea about "the properties". I can see it creates an array. It's fast as you say, so no problem about checking with every arrow key or key press.

Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 9:01 pm
by kaveh1000
Hi Jacqueline
As a follow-up, how do you compare two arrays? I tried
Code: Select all
if the properties of array_one is the properties of array_two...
but it is showing them not to be the same although they should be. I have a mental block with arrays. Any hints appreciated!
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 9:22 pm
by Klaus
Maybe just:
?
But I would probably only compare the HTMLTEXT of your field(s).
That will surely change when the formatting changes.
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 10:22 pm
by jacque
Klaus is right, just check if tArray1 = tArray2.
@Klaus, checking only the htmltext won't catch if the field is resized.
Re: Detecting change to FormattedText
Posted: Sun Oct 18, 2020 10:33 pm
by kaveh1000
Thank you both. Always learn a lot here. I used "=" and it is not giving me the result intended so will do more testing. And will think about the HTMLText too...