w click,
I assume that you are using a utf8 font, since you tried utf8length. But afterward you are still doing ascii lengths ... length(Memo1.lines. Your length must always be utf8length, because utf8 uses multiple characters for one character.
Rick