Hello everybody!
Maybe somebody finds this trick useful:
(... and maybe someone finds a trap, I haven't seen?)
I make heavy use of styled EditFields in my project. After playing
around, I found out that the call of the method...
aNumberOfParagraphs = anEditField.StyledText.ParagraphCount()
... is very time consuming. About a second (!) for 30 paragraphs on
a 1,25 GHz G4.
Because I have to test the number of paragraphs after each keystroke,
you can imagine that this timeframe isn't acceptable at all.
When I count the EndOfLines in my text with ...
aNumberOfParagraphs = CountFields(anEditField.Text, EndOfLine)
... I get (almost) the right value. I just recognized that "empty"
lines in the text don't generate a paragraph in a styled EditField.
So I removed them before counting ...
aNumberOfParagraphs = CountFields(ReplaceAll(aField.Text,
(EndOfLine + EndOfLine), EndOfLine), EndOfLine)
This was almost working, I just saw that multiple empty lines in a
row were not eliminated right. Using a grep sequence finally solved
it...
aRegEx.SearchPattern = "^[\f\n\r]+"
aRegEx.ReplacementPattern = ""
aTextToCount = aField.Text
do
aRegExMatch=aRegEx.Search(aTextToCount)
if (aRegExMatch <> Nil) then
aTextToCount = aRegEx.Replace(aTextToCount)
end
loop until (aRegExMatch = Nil)
aParaLastIndex = CountFields(aTextToCount, EndOfLine)
In my tests the above CountFields() call always returns the same
values as the ParagraphCount() call. It needs always a processing
time of about 1 tick (1/60 of a second), with up to 70 paragraphs and
16,000 chars tested.
Maybe you want to replace the ParagraphCount() calls in your code and
try it. I would be very interested in feedback. Can I trust this
"work-around"? Does someone has any objections arising, I do not see?
Thanks and best wishes,
Marcel
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>