Headers and Footers

This example shows how to use headers and footers. The source code is contained in the Samples\Delphi\Headers sample source directory.

TX supports headers as well as footers. You also have the ability to create a different header or footer for the first page.

The Sample Program

To insert a header or footer in the example, click on Insert and choose one of the four possible options. The code that is executed when clicking on one of the menu items is almost the same. For the Header menu item it looks as shown below. The line

TXTextControl1.HeaderFooter := TXTextControl1.HeaderFooter + txHeader;

informs Text Control that a header should be added to the current settings.

Setting the HeaderFooterStyle property to txMouseClick enables the user to activate the header with a single click rather than a double-click. Activating a header or footer with a double-click is Text Control's default setting. More information about how to use headers and footers and a list of all properties, methods and events that can be used with headers and footers, can be found in the chapter Technical Articles - Headers and Footers.

When using properties, Text Control distinguishes between the main text and headers or footers. To switch between these different independent text parts, Text Control provides the HeaderFooterSelect method:

TXTextControl1.HeaderFooterSelect (txHeader);
TXTextControl1.SelText := 'Header';
TXTextControl1.HeaderFooterSelect (0);

This code selects the header, so that the following code affects the header and then sets the headers text. Finally the mode is reset to zero using the HeaderFooterSelect method. More information about programming with headers and footers see the chapter Technical Articles - Headers and Footers - Programming Headers and Footers.

A header or footer is activated from programming code using the HeaderFooterActivate method. To delete a header or footer, simply substract the txHeader constant from the current HeaderFooter settings. The following is the complete code of the menu item:

procedure TForm1.Header1Click(Sender: TObject);
   If Header1.Checked = False Then begin
         := TXTextControl1.HeaderFooter + txHeader;
      TXTextControl1.HeaderFooterSelect (txHeader);
      TXTextControl1.SelText := 'Header';
      TXTextControl1.HeaderFooterActivate (txHeader);
      Header1.Checked := True;
   end Else begin
         := TXTextControl1.HeaderFooter - txHeader;
      Header1.Checked := False;