Page 1 of 1

How to Save and Load TRiceView as TStream?

Posted: Sun May 30, 2010 10:27 pm
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

Posted: Mon May 31, 2010 2:33 pm
by Sergey Tkachenko
1) Add
LocalStream.Position := 0
before
Parameters[Tag].LoadFromStream(LocalStream, ftBlob);

2) Add
RichViewEdit1.Format
after
RichViewEdit1.LoadRTFFromStream(LocalStream);

Posted: Wed Jun 02, 2010 5:50 pm
by ekoindri
Execelent !.

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

King regards,


Eko Indriyawan