How to Save and Load TRiceView as TStream?

General TRichView support forum. Please post your questions here
Post Reply
ekoindri
Posts: 19
Joined: Sun May 30, 2010 10:00 pm
Location: Indonesia

How to Save and Load TRiceView as TStream?

Post by ekoindri »

I have tried to create a project that having purpose to save and
load TRichView as TStream.

Code for saving TRichView:

Code: Select all

var
  LocalStream: TStream;
begin
LocalStream := TMemoryStream.Create;
with SP_217SAVE do
  begin
  RichViewEdit1.SaveRTFToStream(LocalStream, False);
  Tag := 0;
  Tag := Tag + 1;
  Parameters[Tag].Value := 'TEST';
  Tag := Tag + 1;
  Parameters[Tag].Value := 'TEST';
  Tag := Tag + 1;
  Parameters[Tag].LoadFromStream(LocalStream, ftBlob);
  ExecProc;
  end;
LocalStream.Free;
end;
code for load:

Code: Select all

var
  LocalStream: TStream;
begin
with SP_217DATA do
  begin
  Tag := 0;
  Tag := Tag + 1;
  Parameters[Tag].Value := 'TEST';
  Close;
  Open;
  LocalStream := SP_217DATA.CreateBlobStream(SP_217DATACOMPONENT_DATA, bmRead);
  LocalStream.Position := 0;
  RichViewEdit1.Clear;
  RichViewEdit1.LoadRTFFromStream(LocalStream);
  end;
end;
I want to provide the information when I run my application.

1. I have compiled my project successfully.
2. I also have saved the TRichView to database successfully.
3. When I tried to load the stream from database, I didn't get the error
message, but I didn't see anything in my TRichView.

From code above, Are there any something missing?

Any help or direction is greatly appreciated!

Regards,


Eko Indriyawan
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) Add
LocalStream.Position := 0
before
Parameters[Tag].LoadFromStream(LocalStream, ftBlob);

2) Add
RichViewEdit1.Format
after
RichViewEdit1.LoadRTFFromStream(LocalStream);
ekoindri
Posts: 19
Joined: Sun May 30, 2010 10:00 pm
Location: Indonesia

Post by ekoindri »

Execelent !.

It works perfectly. I can save any rtf file to database and load it to
TRichView.

King regards,


Eko Indriyawan
Post Reply