Position of merge field in OnGetMailMergeText

  • Is there any way of determining the character position of the field being evaluated in the event OnGetMailMergeText?

    I need to store additional data that is held independently of the text document but points to the start of the position the text was inserted.

    I have tried to search for the text held in Contents.OldText but it appears this is removed from the RTF before the call. It also appears that CPPosition does not point to the location as I also tried using this.

    Any help would be gratefully received.

  • Sorry mistype of the event name, it is OnMailMergeGetText not OnGetMailMergeText.

    Thanks for the response Julian, however TWPMMInsertTextContents does not appear to have a property or method called MergePara or MergeParaPos in the version I am using.

    Paul

    • Offizieller Beitrag
    Zitat von Paul Brace

    Sorry mistype of the event name, it is OnMailMergeGetText not OnGetMailMergeText.

    Thanks for the response Julian, however TWPMMInsertTextContents does not appear to have a property or method called MergePara or MergeParaPos in the version I am using.

    No, not in V4.

    You have access to

    property pMergeAttr: PTAttr
    property pMergePar: PTParagraph

    The variables
    FpMergeLin: PTLine;
    FpMergePos: Integer;

    are private. If you have PRO version You can make them public.

    Julian

  • Julian,

    Thanks for that. I have the PRO version and have exposed the variables as properties (MergeLine and MergePosition, and can access them. However I still have a problem :( .

    I need to get the absolute position of the field in the document and this gives me the postion in the paragraph, the line and the position in line. I therefore have tried a number of ways of calculating the absolute position and drawn a blank. The initial function I called was from the original WP object:

    Txt: TWPRichText;

    Txt.GetPositionOfParLin(Contents.pMergePar,
    Contents.MergeLine,
    Contents.MergePosition);

    This returns -1. It appears that the calling WP object does not contain valid data while in the process of merging the text.

    Any thoughts on how I can obtain the absolute position from these?

    Thanks
    Paul

    • Offizieller Beitrag

    Hi,

    to convert the par/lin/pos tripple into X,Y coordinates you can use the method GetPointFromParLin.

    Please note that this is position on screen.

  • The problem is that the original RTF Object is invalid while merge is called and hence these calls do not appear to be available. It was the absolute position in the text I was after not the screen position. But not to worry I have just finished coding a work around by creating an array with the start positions of all merge fields before calling MergeText and then adjusting subsequent start positions for the length of the text inserted - now working as I need it.

    Thanks for your help.

    Paul