Different header and footer depending on text on page:

Tips for WPTools - please <b>no</b> Questions without Answers! Replies are possible.
wpsupport
Site Admin
Posts: 7346
Joined: Fri Oct 24, 2003 4:06 pm
Contact:

Different header and footer depending on text on page:

Postby wpsupport » Tue Nov 11, 2003 3:57 pm

Create different header and footer as 'named' text:

Code: Select all

  // Generate simplyfied header and footer
  WPRichText1.HeaderFooter.Get(wpIsHeader, wpraNamed, 'ONE').RtfText.AsString :=
    'Dies ist der Header ONE';
  WPRichText1.HeaderFooter.Get(wpIsHeader, wpraNamed, 'TWO').RtfText.AsString :=
    'Dies ist der Header TWO';
  WPRichText1.HeaderFooter.Get(wpIsHeader, wpraNamed, 'THREE').RtfText.AsString :=
    'Dies ist der Header THREE';
  WPRichText1.HeaderFooter.Get(wpIsFooter, wpraNamed, 'ONE').RtfText.AsString :=
    'Dies ist der Footer ONE';
  WPRichText1.HeaderFooter.Get(wpIsFooter, wpraNamed, 'TWO').RtfText.AsString :=
    'Dies ist der Footer TWO';
  WPRichText1.HeaderFooter.Get(wpIsFooter, wpraNamed, 'THREE').RtfText.AsString :=
    'Dies ist der Footer THREE';


In the event WPRichText1GetSpecialText you can activate one of the above texts using this code:

Code: Select all

 if WPFindTxtOnPage(WPRichText1,par,lin,'ONE',true) then
  begin
     SpecialText := WPRichText1.HeaderFooter.Get(Kind, wpraNamed, 'ONE');
  end
  else if WPFindTxtOnPage(WPRichText1,par,lin,'TWO',true) then
  begin
     SpecialText := WPRichText1.HeaderFooter.Get(Kind, wpraNamed, 'TWO');
  end ..


The code above uses an utility function which checks if a certain text exists within one line on a certain page. If 'scan=true' it finds the text anywher in the line, otherwise only at the start.

Code: Select all

function WPFindTxtOnPage(wp: TWPCustomRichText; apar: PTParagraph; alin: PTLine; Text: string; Scan: Boolean): Boolean;
var
  par: PTparagraph;
  lin: PTLine;
  len: INteger;
  pageno: Integer;
  i: Integer;
  pc: PChar;
begin
  if alin = nil then raise Exception.Create('Wrong param lin');
  pageno := alin^.pagenum;
  par := wp.FirstPar;
  len := Length(Text);
  Result := FALSE;
  while par <> nil do
  begin
    lin := par^.line;
    while lin <> nil do
    begin
      if lin^.pagenum = pageno then
      begin
         // Find the text anywhere in the line
        if Scan then
        begin
          pc := lin^.pc;
          for i := 0 to lin^.plen - len + 1 do
            if StrLComp(pc, PChar(text), len) = 0 then
            begin
              Result := TRUE;
              break;
            end else inc(pc);
        end
        else // Only expect text at start of line
          if StrLComp(lin^.pc, PChar(text), len) = 0 then Result := TRUE;   
        if Result then break;
      end;
      // Next
      lin := lin^.next;
    end;
    par := par^.next;
  end;
end;


NOTE: This unit will be in V4.2a and higher (unit WPRich.PAS)

Leo W. Beckham
Posts: 1
Joined: Thu Feb 26, 2004 5:49 pm

HEADERS FOOTERS BY PAGE KEYWORD DO NOT DISPLAY IN THE EDITOR

Postby Leo W. Beckham » Fri Feb 27, 2004 5:28 pm

The code provided was implemented to get special text and four keywords were used to search for the header footers. Each keyword was found on the page and during print preview the headers and footers could be viewed but not in the open body of the editor.

When placing a keyword such as "ONE" on a page and backspacing out letters it could be seen that a print change was occuring in the header, and a small blur appeared as if the system was trying show the header. The blur would disappear when the full word was typed, for example as ONE; once the last letter was typed, the header cleared indicating that the read of the keyword was successful.

How can I get the headers and footers using code as provided in the solution to show in the body of the editor?

vendre
Posts: 1
Joined: Wed Sep 13, 2006 6:25 pm

Postby vendre » Wed Sep 13, 2006 6:27 pm

it has these functionalities in version 3?

wpsupport
Site Admin
Posts: 7346
Joined: Fri Oct 24, 2003 4:06 pm
Contact:

Postby wpsupport » Fri Sep 15, 2006 2:37 am

Hi,

no in V3 you cannot do it. The best is V5 anyways since there the header and footer are editable WYSIWYG in page layout mode.

Julian


Return to “FAQ WPTools 3+4”



Who is online

Users browsing this forum: No registered users and 1 guest