Page 1 of 1

[Example] How to combine several documents in one

Posted: Tue Oct 25, 2005 9:20 pm
by Sergey Tkachenko

Code: Select all

procedure AddDoc(const FileName: String; rv: TCustomRichView);
var Stream: TFileStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead);
  rv.InsertRVFFromStream(Stream, rv.ItemCount);
  Stream.Free;
end;

  ...

  RichView1.Clear;
  RichView1.DeleteUnusedStyles(True, True, True);
  AddDoc('c:\file1.rvf', RichView1);
  AddDoc('c:\file2.rvf', RichView1);
  AddDoc('c:\file3.rvf', RichView1);
  RichView1.Format;
If you want to add page breaks between documents, use the following code

Code: Select all

procedure AddDoc(const FileName: String; rv: TCustomRichView); 
var Stream: TFileStream; 
  ItemCount: Integer;
begin 
  ItemCount := rv.ItemCount;
  Stream := TFileStream.Create(FileName, fmOpenRead); 
  rv.InsertRVFFromStream(Stream, rv.ItemCount); 
  Stream.Free; 
  if (ItemCount>0)  and (ItemCount<rv.ItemCount) then
    rv.PageBreaksBeforeItems[ItemCount] := True;
end;

Posted: Thu Nov 24, 2005 10:49 am
by Guest
Hello Sergey,

How can I combine several RTFs into a single file - the example is only for RVFs & I cannot see any procedure like InsertRTFFromStream...

Thanks,

Fiachra

Posted: Thu Nov 24, 2005 3:10 pm
by Guest
Don't worry about that question Sergey,

I've gotten around it by loading my RTFs (one at a time) into a RichView and saving them as RVFs which I then load as per your original example. It's a bit convoluted but it works!

Thanks anyway,

Fiachra

Posted: Thu Nov 24, 2005 8:59 pm
by Sergey Tkachenko
It's not necessary. You can use LoadRTF/LoadRTFFromStream.
Unlike LoadRVF/LoadRVFFromStream they
- do not clear trichview,
- cannot replace collection of styles, they can only add new styles.

So you can use them to load several documents.