Format a variable

General TRichView support forum. Please post your questions here
Post Reply
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Format a variable

Post by leandersantosm »

Hello
I would like to know if there is some variable that can receive a formatted text.
If yes, can you post some example of how can I use it?
Thanks.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

What type of variable?

You can store RVF document in a variable of TMemoryStream type.
If streams are not ok, you can then copy it to a string variable.
leandersantosm
Posts: 20
Joined: Fri Jun 03, 2011 8:33 pm

Post by leandersantosm »

But if I copy a string formatted into a string variable, the formatation will keep stored too?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Delphi string can contain arbitrary binary data, so you can store data in RVF format in a string.

The code below uses TRVAnsiString type (String for Delphi 4-2007, AnsiString for Delphi 2009-XE)

Code: Select all

uses RVTypes;
function SaveToSting(rv: TCustomRichView): TRVAnsiString;
var Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  rv.SaveRVFToStream(Stream, False);
  SetLength(Result, Stream.Size);
  Stream.Position := 0;
  Stream.ReadBuffer(PRVAnsiChar(Result)^, Length(Result));
  Stream.Free;
end;

Code: Select all

procedure LoadFromString(rv: TCustomRichView; const s: TRVAnsiString);
var Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  Stream.WriteBuffer(PRVAnsiChar(s)^, Length(s));
  Stream.Position := 0;
  rv.LoadRVFFromStream(Stream);
  Stream.Free;
  rv.Format;
end;
Post Reply