Get text/rtf in local variable

General TRichView support forum. Please post your questions here
Post Reply
retwas
Posts: 39
Joined: Tue May 21, 2013 1:41 pm

Get text/rtf in local variable

Post by retwas »

Hi,

I have a RichViewEditor and a local variable rveText : string;

How can I put the text or the rtf in this variable ?

I didn't find any RichViewEditor.gettext or other .. :(

Thanks !
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As for plain text - you can use GetAllText from RVGetTextW unit (if you need Unicode string result) or from RVGetText unit (if you need ANSI text)

As for RTF string:

Code: Select all

uses RVTypes; 

function GetRTFString(rv: TCustomRichView): String; 
var Stream: TMemoryStream; 
     s: TRVAnsiString; 
begin 
  Stream := TMemoryStream.Create; 
  rv.SaveRTFToStream(Stream, False); 
  Stream.Position := 0; 
  SetLength(s, Stream.Size); 
  Stream.ReadBuffer(PRVAnsiChar(s)^, Length(s)); 
  Stream.Free; 
  Result := String(s); 
end;
rafakwolf
Posts: 30
Joined: Tue Sep 27, 2011 11:39 am

Get RTF text

Post by rafakwolf »

Hello...

i'm trying to use this function, but the result is not as i need.

Into my RTF text the word "PARÓQUIA" is "PAR\u211 \'d3QUIA"

It is unicode characters ?

Can i get the RTF without them ?

Thanks!
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, you cannot.
TRichView always saves Unicode characters having codes greater than 127 as RTF Unicode characters.
You can only remove non-Unicode duplicates of characters (\'d3 in you example), exclude rvrtfDuplicateUnicode from RTFOptions properties.

Saving Unicode characters as Unicode characters in RTF is necessary.
If we would save only non-Unicode duplicate (\'d3), it can be read correctly only if its Charset is specified correctly. It is not necessary so in TRichView Unicode documents.

And RTF specification does not allow saving characters having codes greater than 127 as they are.
rafakwolf
Posts: 30
Joined: Tue Sep 27, 2011 11:39 am

RTF Documentos

Post by rafakwolf »

OK, thanks for your attention
Post Reply