Merge Field to include Superscript

  • Hi,

    The following doesn't work. Could you please tell me how best to do this?

    if (InspName=eapStrTodaysDateInFull) then
    begin
    DecodeDate(Date,Y,M,D);
    case D of
    1,21,31:S:='st';
    2,22:S:='nd';
    3,23:S:='rd';
    else
    S:='th';
    end;
    Contents.StringValue:='';
    Contents.MergePar.Append(IntToStr(D));
    Contents.MergePar.AppendChar(S[1],WPSTY_SUPERSCRIPT);
    Contents.MergePar.AppendChar(S[2],WPSTY_SUPERSCRIPT);
    Contents.MergePar.Append(' '+FormatDateTime('mmmm yyyy',Date));
    end else
    ...

    Thanks,

    Ken

    • Offizieller Beitrag

    Hi,

    This code cannot work since it tries to append the text to the current paragraph instead of inserting it into the field.

    Further more will the code

    Zitat

    Contents.MergePar.AppendChar(S[1],WPSTY_SUPERSCRIPT);

    not append a character in superscript style. The CharAttr used by AppendChar is not the same as the CharacterStyle. It is an index into the attribute cache - the demo unit WPCreateDemoText of the demo CreateTable shows how this works:

    Zitat

    cha := RTFMemo.HeaderFooter.RTFProps.AttrHelper;
    cha.Clear;
    cha.SetFontName('Times New Roman');
    cha.SetFontSize(12);
    HeadlineA := cha.CharAttr;


    HeadlineA can be the used with AppendChar.

    To solve your problem it would be the easiest to create a small RTF string and assign it to StringValue.

    '{\rtf{' + IntToStr(D) + '{\super ' + S[1] + '}{\sub ' + S[2] +
    '} ' + FormatDateTime('mmmm yyyy',Date).

    Regards,
    Julian