Problem with greek characters in ver 6.07

  • I have an wprichtext control named Test.

    I use Delphi 2007

    I do this simple code
    Test.Text := 'Δοκιμή' --> greek characters.

    but in wprichtext i get invalid characters.
    when i try this code

    Test.Memo._CodePage = 1253;
    Test.Text := 'Δοκιμή' --> greek characters.

    is see then text normal but when i call this line

    Showmessage(Test.Lines.Text) i get invalid characters.

    Is any solution for this?

    Thanks in advanced.

    • Offizieller Beitrag

    Hi,

    I am not so sure - how do you enter such unicode values in Delphi?

    Your code is otherwise ok, internally it translates into a loadfromstream with the codepage attribute.

    You can follow the code into WPIOANSI.PAS in
    function TWPTextReader.Parse(datastream: TStream): TWPRTFDataBlock;

    and see how it is read. Here it would be also possible to see what actually was assigned.

    Your samples from here do not serve well as example, I cannot paste them into a project.

    Julian

  • Hi,
    Thanks for your reply

    "I am not so sure - how do you enter such unicode values in Delphi? "

    This characters isn't Unicode it's just ASCII chars above 127


    "You can follow the code into WPIOANSI.PAS in
    function TWPTextReader.Parse(datastream: TStream): TWPRTFDataBlock;"

    I see it calls PrintAByte but i can't see what happens next because i have WPToos standard license - no full source.

    Can i ask if PrintAByte do any convertions with ASCII chars above 127?

    Thanks in advanced

  • Hi,

    with codepage 1253

    if you convert my ASCII char into WideChar (my Ascii char 196 will become 916 into wide).

    so when i call ActiveText.Lines.Text i get invalid characters.

    Is ActiveText.Lines.Text do some conversion?

  • Hi,

    Sample code to test

    WPRichText1.Memo._CodePage := 1253;
    WPRichText1.Text := #916; --> ASCII 196
    ShowMessage(WPRichText1.Lines.Text);

    Try to run this code and you will see that:

    "WPRichText1.Lines.Text"
    returns back ASCII char 148 which is invalid.
    So some invalid convert is happening into
    WPRichText1.Lines.Text when you have non
    English characters.

    Thanks in advanced.

    • Offizieller Beitrag

    Hi,

    I first though 916 was a typo.

    When You assign to "WPRichText.Text" You are actually using the ANSI reader. Lines.Text is not the same, it just uses the singly byte values stored in TStrings.

    So the code

    WPRichText1.Memo._CodePage := 1253;
    WPRichText1.Text := #916; --> ASCII 196

    cannot work. 916 does not fit into one byte.

    But You can do this

    WPRichText1.Memo._CodePage := 1253;
    WPRichText1.Text := #196;

    and that in fact creates the unicode character 916 in the text buffer.

    When You now do a

    ShowMessage(IntToStr(Integer(WPRichText1.Text[1])));

    You get back the character 196 since the code page is still selected to be 1253.

    I would rather suggest to use the format string 'ANSI-codepage1253', in this simple example this would result in the code

    WPRichText1.LoadFromString( #196, 'ANSI-codepage1253');
    ShowMessage(IntToStr(Integer(WPRichText1.AsANSIString('ANSI-codepage1253',false)[1])));

  • Hi,

    Since wptools converts all characters with MultiByteToWideChar
    i can't use WPRichText.Lines.Text or WPRichText.Lines[Index]

    I must change all my application not to use WPRichText.Lines property
    since i don't use English characters.

    am i correct?

    • Offizieller Beitrag

    Hi,

    May answer was to not use WPRichText.Lines.Text. Lines.Text is not implemented by WPTools' code, it is implemented by the standard TStrings VCL code.

    If you use WPRichText.Text you use WPTools code and the internal unicode to codepage conversion which was implemented in the ANSI reader/writer.

    You also should not use Lines[], You can use the paragraph structures directly to extract the text. I am thinking of adding a codepage property to Lines, but currently its not there.

    Julian

  • "May answer was to not use WPRichText.Lines.Text. Lines.Text is not implemented by WPTools' code, it is implemented by the standard TStrings VCL code."

    Hello,
    I try this with Delphi 2010.

    WPRichText.Lines.Text with non english characters returns wrong result.
    Ok i understand that in Delphi 2007 Lines implemented by the standard TStrings and don't support unicode, but in delphi 2010 why is this happening?

    As is can see WPRichText.Lines.Text calls ...ActiveText.Lines
    where ActiveText.Lines is TWPRtfStrings so
    i suppose (i don't have the source to see) WPRichText.Lines.Text do some wrong conversions?

  • Thanks for you response.

    It's very difficult for me to change now at this time the way the source code works (big projects). In my code i use wptools like this way: "xcomponent.lines[nFor]".
    So i suppose that this code in Delphi 2010 at least should
    works as expected.


    Thanks in advanced.