- Official Post
Create different header and footer as 'named' text:
Code
// 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
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
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;
Display More
NOTE: This unit will be in V4.2a and higher (unit WPRich.PAS)