Takes so long to show a RTF 7KB

It takes about 3-4 seconds to show, in a text area, a RTF file of 7.277 bytes. Is it normal?
I’m using the usual code:

… f = SpecialFolder.GetResource(FileName) if f.exists then textData = TextInputStream.open(f) TextArea1.StyledText.RTFData = textData.ReadAll textData.Close end if

what os are you on ?
its reasonably well known that Xojo’s RTF is kind of slow AND that is does not support the full RTF spec
Just FYI

MacOS 10.14.5

depending on what you’re trying to do with the RTF data there may be better alternatives - esp since Textarea’s RTF support is not complete. You only get what styling etc that a TextArea can support.
There are alternatives depending on whether your app will / wont be x-platform.
BKeeneys formatted text control is one that provides more complete RTF support

Xojo’s RTF handling is slow (and gets exponentially slower as the file gets bigger) but you can speed it up massively.

For one thing this might still work for loading and saving: https://forum.xojo.com/8585-textarea-and-rtf

Also try these two extension methods:

[code]Sub BeginFastEditing(Extends ta As TextArea)
#If TargetMacOS Then

Dim docView As Integer = ta.DocumentView
Dim storage As Integer = ta.TextStorage( docView )

Declare Sub beginEditing Lib "AppKit" Selector "beginEditing" ( obj As Integer )
beginEditing( storage )

#Endif
End Sub[/code]

[code]Sub EndFastEditing(Extends ta As TextArea)
#If TargetMacOS Then

Dim docView As Integer = ta.DocumentView
Dim storage As Integer = ta.TextStorage( docView )

Declare Sub endEditing Lib "AppKit" Selector "endEditing" ( obj As Integer )
endEditing( storage )

#Endif
End Sub[/code]

So to combine them simply do

ExampleTextArea.BeginFastEditing // load your RTF ExampleTextArea.EndFastEditing

Sorry Markus, I probably don’t understand well, but when I try these methods I get an error:

ExtendArea.EndFastEditing, line 3 Type "TextArea" has no member named "DocumentView" Dim docView As Integer = ta.DocumentView ExtendArea.EndFastEditing, line 4 Type "TextArea" has no member named "TextStorage" Dim storage As Integer = ta.TextStorage( docView )

Both methods are defined in a Module.

You forgot to read the provided link (read Markus entry once more). Read there and come back here if you are still in trouble.

Sorry Emile, I already read the post linked and added the two methods as Sam Rowlands posted. Those methods declare the Function documentView and others, but I finally commented all methods contains because they give me more errors.

rectification:
The code provided by the linked to Sam Rowlands works, and load a RTF much more quickly.
The code by Markus I missed how to implement it

You noticed that the error is on an API declared in Sam code ?

This means: add Sam’s API declare code and Markus one will work too.

Note: I do not really read the other thread, so my comment above may not be complete (I hope it is not misleading).

No, no, the Sam code works great and it’s just what I needed. I already included in my app.

But I would like to understand Markus code, I assume it use the Sam’s API declarations, but I do not know how make his code “know this”. Understanding code is, for me, I way to learn.

[quote=446028:@Enric Herrera]ExtendArea.EndFastEditing, line 3
Type “TextArea” has no member named “DocumentView”[/quote]
DocumentView is a name of an API. When I get an eye on Sam’s conversation, I noticed the Declare.

That declare do not exist in Markus code.

That is what I wanted to say earlier: add the declare to the API you will find in Sam’s code and place it in Markus code and the error will vanish.

Did you try binaryStream instead of TextInputStream?

Did you try MBS Xojo Plugins?

WinRTFDataMBS(SelectionOnly as boolean = false) as string

And

RTFDataMBS as Memoryblock
For MacOS.

See
https://www.monkeybreadsoftware.net/class-textarea.shtml

Hi Enric,

sorry, was a few days off my Mac. The missing bit is

Public Function DocumentView(Extends ta As TextArea) as Integer #If TargetMacOS Then Declare Function documentView Lib "AppKit" Selector "documentView" ( obj As Integer ) As Integer Return documentView( ta.Handle ) #Endif End Function

Here is an example project so you can copy what you need:

https://www.dropbox.com/s/3fi0cdze8fgm93o/FastCocoaTextAreaUpdates%205b.rbp.zip

Thank Markus, with your help and Sam’s API I understood how to make it work. Thanks again.

Btw, the example you linked doesn’t works as it lacks and object: “speedTest”, I tried to add a RTF and name it as SpeedTest, but then it crashes Xojo, it should be a class.

That’s why I said copy and not run :wink:

SpeedTest is an external module that I use to measure speed. Try the link again, it should now be included.

Sorry Markus, but I just downloaded and it is not included.