Special character compatibility with WP6

  • Hello. We create documents with special instructions embedded in the text. We use the characters "«" and "»" to reference the instructions. In WP6 these characters were stored internally in the text and could be searched using ActiveText.RTFText.asString then searching for those characters within the string. It appears that in WP7, this is stored internally as &#171 and &#187. This would represent quite a change to existing code. Is there a way to make this backward compatible?

  • Expanding on this: We use codes encased in these brackets in the body of the text for example
    «{Test Code}»
    With version 7, I cannot tell how to determine programmatically that the « or » are used in the text. They apparently do not show up in the ActiveText.RTFText.AsString; or in the richtext.asstring.

    Here is the working code from WP6 which is no longer working in WP7. Any suggestions to get WP7 to find the codes?

    with WPRichText1 do begin
    ActiveText := HeaderFooter.Get(wpIsHeader, wpraOnAllPages);
    HeaderText := ActiveText.RtfText.AsString;
    while Pos('«{', (HeaderText)) > 0 do begin
    c1 := Pos('«{', (HeaderText))+2;
    c2 := Pos('}»', (HeaderText))-1;
    Line := Copy(HeaderText, c1, c2-c1+1);
    Repl := '«{' + Line + '}»';
    with Finder do begin
    ToStart;
    EndAtSpace := True;
    WholeWord := False;
    CaseSensitive := False;
    while Next(repl) do begin
    SelectText;
    SelText := ReplaceVariables('{' + Line + '}') ;
    end;
    EndAtSpace := False;
    end;
    HeaderText := ActiveText.RtfText.AsString;
    end;
    end;

    • Offizieller Beitrag

    You have access to the unit WPIOHTML.pas which writes the HTML code. I assume you use HTML and not RTF since you get this codes.

    I recommend to make a change there, so it writes the form your parser expects.

    It would also be easy to use StrReplace to change the # codes into the ANSI chars you require.


    In genereal I would recommend to do the replacement inside the editor directly.

    You could use the function ReplaceTokes to create merge fields from all text inside of
    «{ and }»

    Then you can use MailMerge to update the text with your data.

  • I am not using HTML. Just dropping the TWPRichText and then getting the text it has stored in memory. There may be a simpler explanation.

    I have a TWpRichtext, and add the text the value "«{ Line }»". When checking the value of the text in the control with wprichtext1.asstring, the « and » characters are not in the asString. So apparently there is no way to check for these characters in the text, correct?

    So even the stringrepalce you recommended below does not work because it will not find the text to do the replacement on.

    Is there a way to have the richtext identify the «?

    thanks,

    D____

    • Offizieller Beitrag

    From your mail I learned that you are using WPTools format.

    I don't understand why StringReplace could not work since the insertion of &#171 is consistent.

    In my mail I recommended to modify WPIOWPTools.pas:

    function TWPTOOLSWriter.WriteChar(aChar: Word): Boolean;
    begin
    if (aChar<>171) and (aChar<>172) then
    Result := WriteHTMLChar(WideChar(aChar))
    else Result := inherited WriteChar(aChar);
    end;

    This makes sure those special characters are not written as HTML entity.