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;
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;