LoadCustomFormat & SaveCustomFormat on DBRichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
merlinofchaos
Posts: 1
Joined: Wed Feb 11, 2015 7:55 am

LoadCustomFormat & SaveCustomFormat on DBRichViewEdit

Post by merlinofchaos »

Hello,

I'm trying to zip stream befor recording and unzip it on reading. About backing everything is OK, but when you try to load it in DBRichViewEdit by LoadCustomFormat text on edit stay empty....

My functions is:

Code: Select all

procedure Tfe_DocEdit.RichViewEdit1LoadCustomFormat(Sender: TCustomRichView;
  Stream: TStream; var DoDefault: Boolean);
var
  AbUnZ : TAbUnZipper;
  MS : TMemoryStream;
  StreamHeader : Int64;
begin
  inherited;

  StreamHeader:= 0;

  if (Stream as TMemoryStream).Size > 10 then
    begin
      (Stream as TMemoryStream).Position:=0;
      (Stream as TMemoryStream).Read(StreamHeader,4);
    end;

  // Zip signature
  if (StreamHeader = 67324752) then
    begin
      MS:= TMemoryStream.Create;

      try
        AbUnZ:= TAbUnZipper.Create(Nil);
        AbUnZ.Stream:=
          (Stream as TMemoryStream);

        AbUnZ.ExtractToStream(AbUnZ.Items[0].FileName,MS);

        MS.Position:= 0;

        (Sender as TDBRichViewEdit).InsertRTFFromStreamEd(MS);

        // It's from debug- file is corectly unziped
        MS.SaveToFile('D:\ZZRtf' + FormatDateTime('ddmmyyhhmmss',now) + '.rtf');

        Sender.SetSelectionBounds(0,0,0,0);

        DoDefault:= False;
      finally
        FreeAndNil(MS);
        FreeAndNil(AbUnZ);
      end;
    end;
end;
For zip I use (it work):

Code: Select all

procedure Tfe_DocEdit.RichViewEdit1SaveCustomFormat(Sender: TCustomRichView;
  Stream: TStream; var DoDefault: Boolean);
var
  AbZ : TAbZipper;
  SStream : TMemoryStream;
  MS : TMemoryStream;
begin
  AbZ:=
    TAbZipper.Create(nil);

  try
    AbZ.ArchiveType:= atZip;
    AbZ.ForceType:= True;

    MS:= TMemoryStream.Create;
    SStream:= TMemoryStream.Create;

    Sender.SaveRTFToStream(SStream, False);

    AbZ.Stream:= MS;

    AbZ.AddFromStream('zipRTF.rtf', SStream);

    AbZ.Save;

    if (Sender as TDBRichViewEdit).DataSource.DataSet.State in [dsEdit, dsInsert] then
      begin
        (Stream as TMemoryStream).LoadFromStream(MS);
        (Sender as TDBRichViewEdit).DataSource.DataSet.FieldByName('DocFormat').AsInteger:= 2;
      end;

    DoDefault:= False;
  finally
    FreeAndNil(AbZ);
    FreeAndNil(MS);
    FreeAndNil(SStream);
  end;
end;
Any ideas what is wrong in onload function?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Try using LoadRTFFromStream instead of InsertRTFFromStreamEd
Post Reply