How do I save/load a page format

General TRichView support forum. Please post your questions here
Post Reply
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

How do I save/load a page format

Post by vit »

How do I save/load a page format (orientation, margins, size etc)?

I store document in the way:

Code: Select all

procedure TDocEditFrame.SaveFile(const FileName: string);
var
  fs: TFileStream;
begin
  fs := TFileStream.Create(FileName, fmCreate or fmOpenWrite);
  try
    SRVE.RVHeader.SaveRVFToStream(fs, False);
    SRVE.RVFooter.SaveRVFToStream(fs, False);
    SRVE.RichViewEdit.SaveRVFToStream(fs, False);
  finally
    fs.Free;
  end;
end;
And load:

Code: Select all

procedure TDocEditFrame.LoadFile(const FileName: string);
var
  fs: TFileStream;
begin
  fs := TFileStream.Create(FileName, fmOpenRead);
  try
    SRVE.RVHeader.Clear;
    SRVE.RVFooter.Clear;
    SRVE.RichViewEdit.Clear;
    SRVE.RVHeader.LoadRVFFromStream(fs);
    SRVE.RVFooter.LoadRVFFromStream(fs);
    SRVE.RichViewEdit.LoadRVFFromStream(fs);
    SRVE.RVHeader.Format;
    SRVE.RVFooter.Format;
    SRVE.RichViewEdit.Format;
    SRVE.SetRVMargins;
  finally
    fs.Free;
  end;
end;
But the page format doesn't appear.


I'm aware I need to handle TRVAControlPanel.OnMarginsChanged and call SRVE.SetRVMargins from inside. But this event doesn't fire.

So what should I do to save/load the page format?
Sergey Tkachenko
Site Admin
Posts: 17562
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Saving:

Code: Select all

SRVE.RichViewEdit.SaveRVF(FileName, False); 
(you can use TFileStream and SaveRVFToStream, but it is not necesary).

Loading:

Code: Select all

SRVE.Clear;
SRVE.RichViewEdit.LoadRVF(FileName);
SRVE.Format;
Important: use Clear and Format methods of SRVE itself.

Note: TRVAControlPanel.OnMarginsChanged must be used only if loading is made using TrvActionOpen.
Post Reply