Collection HeaderFooter : TWPRTFDataCollection

<< Click to Display Table of Contents >>

Navigation:  Programming > Create text under program control > Header/Footer API >

Collection HeaderFooter : TWPRTFDataCollection

The headers and footers (and also the body and optional texts) are stored in the runtime collection property TWPRichText.HeaderFooter.

 

Example: Copy all header and footer from one editor to another:

 

var i : Integer;

begin

for i:=0 to WPRichText1.HeaderFooter.Count-1 do

if WPRichText1.HeaderFooter[i].Kind in [wpIsHeader, wpIsFooter] then

 WPRichText2.HeaderFooter.Get(WPRichText1.HeaderFooter[i].Kind,

   WPRichText1.HeaderFooter[i].Range, '').RtfText.AsString :=

      WPRichText1.HeaderFooter[i].RTFtext.AsString;

end;

 

This collection manages a list of instances of the class TWPRTFDataBlock. Each instance holds one 'special' text. This text can be used as a header or a footer within the selected range.

 

 TWPRTFDataBlock = class(TCollectionItem)

 ...

published

  property Name: string

  property UsedForSectionID

  property Range: TWPPagePropertyRange

  property Kind: TWPPagePropertyKind

  property RtfText: TWPRTFDataContents

end;

 

 TWPPagePropertyRange =

   (wpraOnAllPages, wpraOnOddPages, wpraOnEvenPages, wpraOnFirstPage,

  // these Modes are not compatible to the RTF Standard !

  // They have priority !!!!

   wpraOnLastPage, wpraNotOnFirstAndLastPages,

   wpraNamed, wpraIgnored, wpraNotOnFirstPage

   ,wpraOnGivenPageNr  // This makes sense only for header and footer. The

   // text is selected by name. The name must be specified

   // as '#' + PageNumber in range [1...] (absolute-not per section!)

   ,wpraTemporary  // Used to create temporary paragraphs for edit fields.

   );

 

 TWPPagePropertyKind = (wpIsBody, wpIsHeader, wpIsFooter,

     wpIsFootnote,       // The last 4 are for internal use only

     wpIsLoadedBody,

     wpIsDeleted,

     wpIsOwnerSelected);

 

 

 TWPRTFDataContents = class(TPersistent)

public

  constructor Create(Source: TWPRTFDataBlock);

  procedure LoadFromStream(Stream: TStream); virtual;

  procedure SaveToStream(Stream: TStream); virtual;

  property  AsString: string read GetAsString write SetAsString;

  procedure Assign(Source: TPersistent); override;

  property  Format: string read FFormat write FFormat;

end;

 

To change the text you can load the text from a stream using Item.RtfText.LoadFromStream or you can simply set or read the property AsString! This string can also be in HTML or WPTOOLS format!

 

The RTFDataCollection provides this functions to find certain header or footer entries. You can of course enumerate all the items using the Items[] array.

 

function Find(Kind: TWPPagePropertyKind; Range: TWPPagePropertyRange;

 

const Name: string = '*'; UsedForSectionID: Integer = 0): TWPRTFDataBlock;

 

procedure DeleteTexts(UsedForSectionID: Integer); overload;

 

procedure DeleteTexts(Kind: TWPPagePropertyKind; UsedForSectionID: Integer); overload;

 

procedure DeleteRTFData(RTFData: TWPRTFDataBlock);

 

procedure DeleteText(Kind: TWPPagePropertyKind; Range: TWPPagePropertyRange; UsedForSectionID: Integer = 0);