Copy/write StyledText.RTFData to file

Hi everybody.

I’m new to xojo and I can’t find a way to save the content of my textarea to a file.

How can you do that?

I have a textarea formatted the way I like, with tabs positioning and everything (normal/bold text, etc.)

In order to see what is xojo writing in the RTF SltyledText, I’d like to write a file (whatever the extention will be) so that I can further analyze its RTF content.

Any hint on how to do that?
I’m in a MacOS Monterey, Xojo 2022 and the app is Desktop.

Many thanks in advance for any suggestions…

Best,
Carlo

Xojo has an introduction-to-xojo book that covers a lot of the basics like this:

@Tim_Parnell Do you know if the book has been updated ? I read it back in 2018, but Xojo changed a lot since.

It certainly looks like the book was updated to me. I’m seeing API 2.0 code, new classes like DateTime, and the PDF modification date is 2022-01-27.

Chapter 9: In & Out will be relevant to those looking to write files. The Hands on with Files section is about saving RTF.

1 Like

I’m actually going through the book right now, and it is very well written and seems to cover a lot of material. There are a few errors, perhaps some of it content leftover from a previous version, but nothing that would prevent someone from figuring it out and moving forward.

As a side note:

I’ve noticed some typos / errors in the docs also - but I hate to be the grammar police and bug someone about it. Is there a low key way of submitting corrections, without it coming across like a bug report?

I kind of wish the docs could be community edited so that we could suggest changes without making a big deal of it. It would also be nice if the docs had a section for input from the experienced Xojo users that showed tips / workarounds / or unusual ways of accomplishing tasks related to the documentation topic. That was something I always enjoyed about the PHP docs (not sure if they are still like that), where they were kind of like living documentation with running comments by users that were very helpful - lots of knowledge shared.

Didn’t mean to derail - just didn’t think this deserved its own topic…

Many thanks for the hint…
truly appreciated.

At page 173 of introduction to programming I am asked:

  1. Add this code to FontMenu’s Pressed event:
    Var myFontCount As Integer
    myFontCount = System.FontCount - 1
    For i As Integer = 0 To myFontCount
    Me.AddRow(System.FontAt(i))
    Next

FontMenu is a popupmenu.
There is not such event handler as Pressed…

What should I do?

I did manage to open and save an RTF file.
This is what happens:
If I create my RTF with MacOS TextEdit, naturally, I can place my tabs wherever I want with whichever direction I like.
Once I have created such file, if I copy it with Command-C and I then paste it into xojo textarea, it shows fine. No differences (in terms of tabs positions and directions. Perfect output.
I then proceed to save the file (from xojo), expecting the resulting rtf file to represent what I had on the screen.
In order to check that, I open the file that I had just saved.
What I get is a totally different look.
All tabs positions have gone ape in terms of positions and directions.

Long Story short, textarea is totally unusable for such a goal.

Is there any plugin available, that you know of, which is considering tabs for RTF files?

If so, I’d love to buy it to see if it solves the issue.

I need to thank you all for the time you wasted on my problem.

Best,

Carlo

Carlo,
puoi provare con l’eccellente codice di Massimo Valle.
(scorri il contenuto del link fin verso la metà)

How do you do that with DesktopTextArea ?

A link to the documentation is enough for me, no code neeeded.

Tutto ciò che ho trovato è

Non ho trovato riferimenti a Massimo Valle
Ho comunque scaricato lo zip.
Nel file .md dice di aprire il file macoslib.rbvcp ma non c’è.
L’unico file che trovo è macoslib.xojo_project che, presumo, sia lo stesso file in xojo anziché in rb.
Se lo lancio, mi da errore in open
dim pdoc as PDFDocument = PDFDocument.CreateFromFolderItem( docfile )
e mi dice che quest iitem non esiste: PDFDocument.CreateFromFolderItem( docfile )
Si trova in QuickStarPDFWIND->Event Handlers->Open
Che posso fare?
Grazie infinite…

Aspetta un pochino che ti preparo qualcosa.

Puoi scaricare l’esempio da dropbox:
https://www.dropbox.com/s/rs8r3gz8ismipj4/TRFtest.zip?raw=1

Nella cartella, ti converrà spostare il file test.rtf sulla scrivania, poi, una volta lanciato il Xojo projext, clicca Open in basso a sn, e seleziona tale file.
Spero il tutto funzioni a dovere.
Ciao.

Riguardo macoslib: siccome lo uso da anni, estraggo solo quello che mi serve.
Lanciando macoslib.xojo_project anche a me l’app va in crash, ma pensavo ciò fosse dovuto al fatto che il mio mac è Intel e uso BigSur.
Ad ogni modo, copiando/incollando le parti necessarie in un tuo progetto dovrebbe funzionare a dovere (almeno a me funziona).
Se in un domani penserai di averne bisogno fammi un fischio, e nel possibile ti darò una mano. Ciao.

la app compilata pare funzionare bene.
il sorgente si ferma in debug quando lo lancio, dopo averlo spostato sul desktop…
Se mi dai una mail, ti mando uno screenshot di come di ferma…
Grazie infinite…
Può essere che non giri con xojo 2022?
Io pure uso un Mac da 27 con Intel, Monterey, preso un mese fa da AppleStore.
Non mi è piaciuto il fatto che con l’M1 non si possa cambiare nulla.

Ti ho inviato una notifica personale contenente il mio indirizzo email.

Mi viene il dubbio che il file, dato che è stato scaricato da Internet, sia in quarantena. Prova ad aprirlo in TextEdit (con doppio click), aggiungere un paio di parole e salvarlo.

Scusami la fosse PHP non avrei problemi ma con xojo sono davvero un neofita…
Sono riuscito a farlo funzionare e fa esattamente ciò che mi occorre.
Mi dispiace ma ora c’è un altro problema…
Ho copiato il Modulo nel mio progetto e altre cose che mi sono portato dietro dal progetto che mi hai inviato.

Considera che ho lasciato tutto come nel tuo progetto, mantenendo gli stessi nomi che hai nel tuo.

Come detto, io sto usando xojo 2022.
Se provo ad inserire il MainMenuBar del tuo nel mio, non funziona.
Pazienza. l’ho tolto anche da mio visto che non mi occorrono menu.
La tua finestra principale (unica) ha il nome Window1 e Super=Window.
Dopo aver copiato tutto ciò che mi occorreva copiare dal tuo al mio, quando provo a lanciarlo mi dice che la Super Window è obsoleta e che dovrebbe essere cambiata in DesktopWindow.
Se la cambio, quindi con Super=DesktopWindow, succede questo:

Mi dice che ci sono 7 errori in openBtn->Pressed
1
Window1.openBtn.Pressed, line 7
Parameter “Parent” expects class Window, but this is class Window1.Window1.
f = dlg.ShowModalWithin(self)
2
Window1.openBtn.Pressed, line 7
Type mismatch error. Expected class FolderItem, but got Int32
f = dlg.ShowModalWithin(self)
3
Window1.openBtn.Pressed, line 11
There is more than one method with this name but this does not match any of the available signatures.
TextArea1RTFValue = t.ReadAll

4
Window1.saveBtn.Pressed, line 4
Parameter “Parent” expects class Window, but this is class Window1.Window1.
var f as folderitem = dlg.ShowModalWithin(self)

5
Window1.saveBtn.Pressed, line 4
Type mismatch error. Expected class FolderItem, but got Int32
var f as folderitem = dlg.ShowModalWithin(self)

6
Window1.saveBtn.Pressed, line 7
There is more than one method with this name but this does not match any of the available signatures.
o.Write TextArea1.RTFValue

7
Window1.saveBtn.Pressed, line 7
Parameter “Line” expects type String, but this is type Int32.
o.Write TextArea1.RTFValue

Anche se ci capisco poco, presumo che l’errore sia uno solo e che a catena genera gli altri.

Allora provo a mettere Super=Window, benché obsoleto e escono altri errori, stavolta 4.
1
Window1.openBtn.Pressed, line 11
There is more than one method with this name but this does not match any of the available signatures.
TextArea1.RTFValue = t.ReadAll

2
Window1.saveBtn.Pressed, line 7
There is more than one method with this name but this does not match any of the available signatures.
o.Write TextArea1.RTFValue

3
Window1.saveBtn.Pressed, line 7
Parameter “Line” expects type String, but this is type Int32.
o.Write TextArea1.RTFValue

4
Window1.Opening Declaration
You cannot implement a nonexistent event
Sub Opening()

Magari è solo una stupidaggine da sistemare ma io non ho proprio esperienza…
Perdonami se rompo…

Appunto, questo è il problema, in quanto il progetto inviato è stato costruito con Xojo 2021 API1.
Sto scaricando Xojo 2022r1 e ti invierò per email lo stesso progetto in API2. Un po’ di pazienza perchè la mia connessione Internet è lenta.

Proj for Xojo 2022 sent by email to OP, but available also at
https://www.dropbox.com/s/s59k8fsub8uxiab/TRFtest2022.zip?raw=1

The original RTF module expects a textArea with Super as TextArea, while Xojo22, in a new project, set a textArea’s Super to DesktopTextArea.
Changing the Super to TextArea, the RTF module works all right, while keeping the Super to DesktopTextArea it breaks the code (the sample on dropbox should work OK!).
I’d appreciate if somebody could fix the code so that the module may work also with a textArea’s Super set to DesktopTextArea.
Thanks.

you should file a feedback case iIMHO if you want it to be fixed !