MergeText in Header, Footer, Body ...

    • Offizieller Beitrag

    Q: How can I merge the fields in different text blocks?

    A: You can use WPRichText.MergeText('', true) to merge the fields in ALL text blocks.

    If you need to limit the merge process to one text block use the MergeText procedure of the TWPRTFDataBlock:

    Code
    function TWPRTFDataBlock.MergeText(
        SenderForCallBack: TObject; 
        CallBack: TWPMailMergeGetTextEvent;
        Readonly: Boolean; 
        const FieldName: string = '';
        StartPar: TParagraph = nil; 
        LastPar: TParagraph = nil): Boolean;

    You will have to pass the callback address, in fact this is your OnMailMergeGetText event procedure.

    Readonly can be set to TRUE if you only want to read the fields (EmbeddedText). FieldName can be used to restrict the merge to certain fields. StartPar and EndPar is only used if you want to merge certain paragraphs.

    So, to merge only the fields in the headers use

    for i:=0 to WPRichText1.HeaderFooter.Count-1 do
    if (WPRichText1.HeaderFooter[i].Kind=wpIsHeader) and
    not (WPRichText1.HeaderFooter[i].IsEmpty) then
    WPRichText1.HeaderFooter[i].MergeText(
    WPRichText1,
    WPRichText1MailMergeGetText,
    false,
    '', nil, nil );

    Julian Ziersch

    [/b]

    • Offizieller Beitrag

    If you want or create a multi letter text (as in MailM4 demo) you will have to use the procedure FastAppendText to copy the text.

    But FastAppendText does not copy the header/footer texts. You need to copy the complete template first and then the letters:

    AllText.AsString := Template.AsString;
    AllText.ClearBody;
    while not Table.EOF do ... // the merge loop

    If you don't see the header/footers in the destination (AllText) please check a) LayoutMode (use FullLayout)
    b) make sure PrintParameter.PrintHeaderFooter is not set to 'never'.

    Header/footer will be bthe same for all texts. Please see 'AppendAsSection' demo which shows how to create a multi section demo, there all parts can have their own header and footers.