Can't see RTF content after successful Read

I’m a seasoned VB6 programmer but new to Xojo.
I can’t for the life of me see where I’m going wrong here - can anyone help, please?
In the Windows version, I’m trying to read an RTF file (originally created by MS Word) into a TextArea. I have experimented with both short (styled) text-only files and with longer ones containing both pictures and styled text.
Here’s a simple example - note that in the Inspector, “Allow Styled Text” is “on” and the “Initial State Value” is “Test”; Xojo documentations tell me that I should also have “Multiline” selected in the Inspector, but I can’t see it, so I tried it programmatically, but it made no difference.
Just to make things simple, I placed this code in the Text Area’s “Key Down” event handler:

// Open a Rich Text File and (for this Test version)
// place content directly onto the Text Area

Dim currentFile As FolderItem
Dim rtfType As New FileType
Dim txtType As New FileType
Dim txtData As TextInputStream

rtfType.Extensions = "rtf"
rtfType.Name = "Rich Text File"
txtType.Extensions = "txt"
txtType.Name = "Text File"

' Limit allowable file types to the above:
currentFile = FolderItem.ShowOpenFileDialog(rtfType + txtType)

' If not Cancelled, read the file and place its file name in window Title:
If currentFile <> Nil Then
  txtData = TextInputStream.Open(currentFile)
  If txtData <> Nil Then
    TextArea1.StyledText.RTFData = txtData.ReadAll
    Self.Title = " (" + currentFile.Name +")"
    MsgBox "File could not be Opened" '(this has never actually happened in this test)
  End If
End If

When the snippet runs, I can enter typed text from the keyboard and I can also paste the short (styled text) file and the long file (with pictures, bullets, tables and colored highlighting all intact and readable) completely successfully but when I read a file, nothing seems to happen other than removing the “Test” text set in the Inspector’s “Initial State Value”.

Am I doing something really dumb here, or is it a system problem? Any workarounds or solutions much appreciated. . .

You need to another property theRTFData as StyledText and the read the contents of the file into that property before assigning it to the textarea’s StyledText:

... theRTFData.RTFData = txtData.ReadAll TextArea1.RTFData = theRTFData TextArea1.Invalidate txtData.Close Self.Title = " (" + currentFile.Name +")" ...

I am quite sure that the documentation do not say images are supported.

RTF implantation in Xojo is a subset of what is available in Word.

Worse: you can paste some rtf data and see what it is, but at save time, you will loose every thing that Xojo does not support.

I was at the point that I created my rtf files with a Xojo made application to save the styled text files using Xojo subset RTF, so I know what I will read (especially with UTF text like accentuated vowel like “éèiçàãñõ” etc).

Now, maybe the situation is better on Windows since the last time I checked…


Thanks for your reply, Tim.

I’ve now tried your suggestion, but the compiler told me that “theRTFData” needed to be declared “As String”, which I then changed it to. Also, I believe that your second line should be “TextArea1.StyledText.RTFData” since “TextArea1.RTFData” gives a runtime error.

Having then run it with these mods, I get a few lines of mangled (styled) text showing, but even this is a bit of improvement compared to the zilch that I previously got!

I don’t really understand what’s going on. I know that the Xojo TextArea control supports a mere subset of Microsoft’s VB6 RTFBox control and, in fact, all I need it to support are the full range of stylised texts (including paragraph alignment but not bullets), but it seems to do so much more than this when content is pasted in and virtually nothing when it is read in. My own code follows the example on Page #154 of the Xojo Introduction to Programming guide, but that seems to be inaccurate and riddled with print (if not logical) errors.

Great if you could let me have your thoughts on the above and many thanks in advance!

Hi Emile, and thanks for your reply.

Disappointing news, but it does confirm my worst suspicions. Surely there must be a solution (other than having to purchase a separate 3rd-party control), or at least an understanding of why pasting works but reading doesn’t???

I’m really liking Xojo as a modern alternative to VB6 - it’s a great approach and has some really sensible ideas and nifty stuff. But I do need solid and stable styled text capability - I can live without the pictures!

If you only need to display (no user editing), you may use styled html files / HTMLViewer.

I do not like that, but if it helps you.

About why paste works ?
Surprising a bit for new comers, but for old people who were here at RTF Subset addition, it is not. And after all, I (we) do not care anymore since I (we) cannot change anything.

Really sorry.

Hi Emile!

My app acts as a kind of Editorial Assistant for writers of novels, who use (normally only one or two of) a plethora of different software (e.g. MS Word, Open Office, Mac Pages and a whole host of specialised 3rd-party creative writing software) running on different platforms (Windows, Linux, Android and macOS). The one thing that they have in common is their history of using RTF files as the everyday interchangeability file format. This means, of course, that styled text is the key functional requirement of the app, which must read from the novelist’s draft file and re-write a Writing Editor’s corrected or marked-up version; unfortunately, using HTML, XML, LaTeX or similar just wouldn’t be accepted by most writers.

Nonetheless, I’ve much appreciated your comments; thank you!

Try this:

It’s licensed as a Library, so if you make changes to the RTFBox then you must publish the source of your version of the RTFBox for 3 years. You must also link to the original and state what you changed. You also have to state the copyright for deblauweg and include the license (

Other than that you don’t have to publish the source of your program other than the RTFBox.

Copy/Paste won’t work, but loading RTF should for the most part work, including pictures.

Hope this helps.

Many thanks for this, Dirk - I’ll take a good look tomorrow, but having just taken a quick lunch-break look at the Readme file, I see it requires various Cocoa and other Mac plug-ins. I’m developing under Windows 10 - is this product cross platform or Mac only, do you know?

It only requires mac plugins if you want to use the mac touchbar.
If you don’t need that make sure to set the clsRTFBox_Data.ALLOW_NSTOUCHBAR to false and no plugin needed.
The only plugin that’s compiled in is the Postgresql plugin that is part of Xojo (and you can remove that if you want because it’s not really used). It’s cross platform (tested on Windows and Mac). It’s been developed by my colleague Gino and is part of the product we make (software for construction companies).

Here’s the simplest example using my code above that I could create:
RTF File Load Example