Jump to content
Squall_FF8

RichEdit with MSSQL

Recommended Posts

Hi guys,
I have a TFDQuerry connected to MSSQL that returns a record with field Test - nvarchar(max).
I would like to be able to Paste a text from Word in a RichEdit and be able to save it (formatted as RTF) in Test and latter on load it from there.
How I can do that? (code snippet)

P.S. If possible I try to use Insert/Update statements, but if I have to - I will use BLOBs. I just dont understand how blobs work in conjunction with normal Insert/Update.

Edited by Squall_FF8

Share this post


Link to post

RTF is encoded in plain ASCII text, where non-ASCII characters are escaped. So, you should not need a blob for this, a simple text field will suffice (although, you might consider a blob if you want to store the RTF using 8bit characters but don't want to use varchar instead of nvarchar).

 

Have you tried simply saving the RTF from the RichEdit into a UnicodeString (ie nvarchar) or AnsiString (ie varchar) variable and then load it back in, without involving a DB at all?  Set the RichEdit.PlainText property to false to tell the RichEdit to act on RTF, and then use the RichEdit.SaveToStream() and RichEdit.LoadFromStream() methods to get and load the RTF.  You can then expand on that logic to introduce text handling with a DB.

Edited by Remy Lebeau

Share this post


Link to post
13 hours ago, Remy Lebeau said:

and then use the RichEdit.SaveToStream() and RichEdit.LoadFromStream() methods to get and load the RTF.  You can then expand on that logic to introduce text handling with a DB.

OK, I did:

// To get RTF
  var Stream := tStringStream.Create;
  Rich.Lines.SaveToStream(Stream);
  Result := QuotedStr(Stream.DataString); // for Insert/Update, the text needs quotes

However when I use the result in Query, I get error - it messes up the syntax of the SQL.
So I inspected the returned DataString ... It seems it uses not just plain text, but control codes: 13, 10, 0. That creates 2 problems:
1. QuotedStr - formats it in Delphi way: 'text'#13#10'text'.... SQL doesn't like that!
2. #0 is considered end of a string (most of the times) and Delphi cuts what follows.

Questions:
- Since when RTF includes control codes (ASCII < 32)? If that is the case then things like `\par` are nonsense.
- The RTF text states version 2.0. Do you know what version of RichEdit Delphi 12+ uses?

 

Quote

RTF is encoded in plain ASCII 

Because of: "{\rtf1\ansi". I'm not familiar with "RTF using 8bit characters". Does Delpji / Windows RichEdit supports that? Do you know of a program that supports that?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×