Append section with individual footer (or header)

<< Click to Display Table of Contents >>

Navigation:  Programming > Sections >

Append section with individual footer (or header)

You can use WPRichText1.ActiveParagraph.StartNewSection to add a new section property object to the current paragraph. The return object will be an object of class TWPRTFSectionProps. In property 'Select' you can change which properties should be used for this section.

 

Using WPRichText1.HeaderFooter.Append you can append a new RTFDataBlock to be used as footer. 'Get' cannot be used, since this will reuse an existing RTFDataBlock.

 

procedure TForm1.PortraitLandscapeClick(Sender: TObject);

var sect : TWPRTFSectionProps;

   footer : TWPRTFDataBlock;

begin

 WPRichText1.CPPosition := MaxInt;

 Inc(c);

// start a section

 sect := WPRichText1.ActiveParagraph.StartNewSection;

 sect.Select := [wpsec_PageSize]; // 1.  (in this order!)

 sect.Landscape := Sender = Landscape; // 2.

 

// Now new page and some text

 WPRichText1.InputString(#12+#32+IntToStr(c)+#13);

 

// also add special header+footer for this section

 footer := WPRichText1.HeaderFooter.Append(wpIsFooter,wpraOnAllPages,'');

 footer.UsedForSectionID := sect.SectionID;

 

 WPRichText1.ActiveText := footer;

 WPRichText1.InputString('Section ' + IntToStr(c) + #9);

 WPRichText1.InputTextFieldName('PAGE');

 

 WPRichText1.ActiveParagraph.TabstopAdd(

   sect.PageWidth-sect.LeftMargin-sect.RightMargin,

   tkRight,

   tkUnderline );

// select body again

 WPRichText1.ActiveText := WPRichText1.BodyText;

end;

 

You can also use this API:

 

function InputSection(Select: TWPRTFSectionPropsSelect = [wpsec_PageSize, wpsec_Margins]): TWPRTFSectionProps;

It returns a new section object.

 

This property can be used to retrieve the current section object:

 

function ActiveSection: TWPRTFSectionProps;