Moved this conversation over to here from the Facebook page, to make it easier to share code and involve more people.
Basically someone on Facebook was enquiring a way to save RTF from a Xojo app, quicker than Xojo’s methods. Here’s some code that will save a RTFD (which can include images) to disk.
[code] Dim nsd as new saveAsDialog
nsd.suggestedFileName = “test.rtfd”
Dim f as folderitem = nsd.showModalwithin( self )
if f <> nil then
declare function documentView lib “AppKit” selector “documentView” ( TextArea as integer ) as integer
declare function writeRTFDToFile lib “AppKit” selector “writeRTFDToFile:atomically:” ( TextArea as integer, file as CFStringRef, atomically as boolean ) as boolean
if writeRTFDToFile( documentView( TextArea1.handle ), f.nativePath, true ) = false then
MsgBox "Sorry, but an error occured."
end if
[code] Dim nod as new openDialog
nod.filter = “???”
Dim f as folderitem = nod.showModalWithin( self )
if f <> nil then
declare function documentView lib “AppKit” selector “documentView” ( TextArea as integer ) as integer
declare function readRTFDFromFile lib “AppKit” selector “readRTFDFromFile:” ( TextArea as integer, file as CFStringRef ) as boolean
if readRTFDFromFile( documentView( TextArea1.handle ), f.nativePath ) = false then
MsgBox "Sorry, but an error occured."
end if
[quote=60542:@Sam Rowlands]Moved this conversation over to here from the Facebook page, to make it easier to share code and involve more people.
[/quote]
Someone should point that person here as I never use Facebook so had no idea folks would / were asking technical questions there
[quote]Antoon Verleysen
Hey everybody. I am new here. I am 67 years old and I live in Belgium. Normaly I speek Dutch. Since many years I program application in VB6 with SQL Server as database. Now I am trying out xojo. There are some good things, but I have a big problem with the use of rich text with a textarea control. (veryyyyyy sloooowwww ! Can I ask help here, or have I to go the xojo-forum. Kind regards. Antoon.[/quote]
Here is that guy from Facebook. Hallo everybody !
I read all the posts regarding this problem. But all the samples use a folderitem.
Is it possible to adapt this code so I can read from and write to a blob- or textfield in a sqlite-databasetable ?
Kind regards. Antoon from Belgium (Aalst)
Sam, I tried out your code. It works GREAT. The code is very fast even for very big data.
But how can I adapt this code to read the data from a database and not from a file.
If that is possible, I should be in seventh heaven !!!
[quote=60666:@Antoon Verleysen]
But how can I adapt this code to read the data from a database and not from a file.
If that is possible, I should be in seventh heaven !!![/quote]
For RTF only (not RTFD) check the code I linked above. There are a couple of methods for get/set data from/to a string.
For RTFD just save the files in a temporary folder and then read it with above method.
@Antoon Verleysen, If you check the link that Massimo pasted above you should find the code for pure RTF. I should have looked in the forums before I posted this as Massimo had solved it a while ago.
@Richard Duke, You got it, OS X only I’m afraid. This code relies on accessing the underlying NSTextView functions on the Mac. I have no idea if there are similar functions on Windows, otherwise just use the Xojo RTF functions or maybe someone else has written one.
I’ve not tried to add an image in a Xojo application. If I drag a image file in, I just get the file name, and I can’t paste images in… Maybe @Joe Ranieri can shed a little bit of light as I’d love to allow my users to insert images too.
Especially now that I know I can load and save RTFD files with images.
Massimo, I pasted your code in my program. But I run it , the following errors occurs :
Module.RTFValue, line 8 - This item does not exist - range.lenght = Len(t.Text)
(in the Function RTFValue…)
Module.RTFValue, line 9 - This item does not exist - range.lenght = Len(t.Text)
(in the Sub RTFValue…)
However in both cases the line just above the ‘error-line’ = Dim range as NSRange
[quote=60894:@Antoon Verleysen]Massimo, I created a NSRange Structure with the following declarations :
location as integer
lenght as integer
For the scope I used Global.[/quote]