Page 1 of 1
Format a variable
Posted: Fri Jun 03, 2011 8:37 pm
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.
Posted: Sat Jun 04, 2011 10:53 am
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.
Posted: Mon Jun 06, 2011 3:58 pm
by leandersantosm
But if I copy a string formatted into a string variable, the formatation will keep stored too?
Posted: Mon Jun 06, 2011 4:47 pm
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;