Appending onPaintPage

General TRichView support forum. Please post your questions here
Post Reply
RichardDufour
Posts: 4
Joined: Mon Nov 24, 2014 4:22 pm

Appending onPaintPage

Post by RichardDufour »

I have 2 ScaleSRichView (ScaleRicheView1 and ScaleRichView2).

In ScaleRichView1, I load some sale data (net, gross, customer info, etc). I also have a custom onPaintPage event to display some header and footers.

Code: Select all

var
  H : Integer;
  Text: String;

begin
  inherited;

  if Prepaint then
    Exit;  // *** EXIT RIGHT HERE ****

  Canvas.Brush.Style := bsSolid;
  Canvas.Brush.Color := clRed;
  Canvas.Font.Assign( ScaleRicheView1 .RichViewEdit.Style.TextStyles[0]) ;

  // Drawing header
  H := ScaleRicheView1 .TopMargin100Pix;
  Text := 'Page ' + IntToStr(PageNo);

  Canvas.FillRect( Rect( PageRect.Left, PageRect.Top, PageRect.Right, PageRect.Top + H ) );

  Canvas.TextOut( ((PageRect.Left + PageRect.Right - Canvas.TextWidth(Text)) div 2),
                  PageRect.Top+H div 2, Text );

  // Drawing footer
  H := ScaleRicheView1 .BottomMargin100Pix;
  Text := 'Sample Footer';

  Canvas.FillRect( Rect(PageRect.Left, PageRect.Bottom - H, PageRect.Right, PageRect.Bottom ) );

  Canvas.TextOut( ((PageRect.Left + PageRect.Right - Canvas.TextWidth(Text)) div 2),
                  PageRect.Bottom - H div 2, Text);

end;
Now, my business logic requires that I display multiple sales into 1 ScaleRichView control. So to do this I used the following code:

Code: Select all

procedure AppendSale;
var
  Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  try
    ScaleRichView1.RichViewEdit.SaveRVFToStream( Stream, False {ASelectionOnly} );
    Stream.Position := 0;

    ScaleRichView2.RichViewEdit.InsertRVFFromStream( Stream, ScaleRichView2.RichViewEdit.ItemCount );

    ScaleRichView2.Format;
  finally
    FreeandNil( Stream );
  end;
end;

procedure DisplaySales;
var
  SaleIndex: Integer;
begin
  for SaleIndex := 0 to Sales.Count -1 do
  begin
    // ... {first load ScaleRichView1 info/data here}, then
    AppendSale;
  end;
end;
Why isn't the customOnPaintPage appended to ScaleRichView2 (it is there on the ScaleRichView1, but never carried over to the ScaleRichView2).


The idea in the end is to have 1 ScaleRichView control that would display a page # footer like (assuming we have 2 sales with 3 pages each):

* Sale 1 *
Page 1 of 3
Page 2 of 3
Page 3 of 3
* Sale 2 *
Page 1 of 3
Page 2 of 3
Page 3 of 3

How can I do this?

Please advise,
Richard
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

File/stream loading methods can load only documents, they cannot load events.

You can modify your code in OnPaintPage event (to use Sender instead of ScaleRichView1 in this code) and assign it both to ScaleRichView1's and ScaleRichView2's OnPaintPage.

New versions of ScaleRichView supports page number and page count fields. However, as I understand, you need to separate your document on sections (one section per sale), and start numbering in each section from the beginning. Unfortunately, sections are not supported, so the only way to do it is drawing all this text yourself. And you need to calculate yourself, on which page which text to write.
Post Reply