[Lazarus] Problems with accented characters

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Sun Mar 7 23:36:05 CET 2010


On Sun, Mar 7, 2010 at 7:29 PM, Silvio Clecio <silvioprog at gmail.com> wrote:
> I'm trying to create a function to replace accented characters by single
> characters, e.g:

Maybe you should show how your code for this is.

The easiest way is making a large if block.

> Code:
> ---------------------------------
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>  Edit2.Text := Edit1.text[1]
> end;
> ---------------------------------

There is no problem here, Lazarus encodes strings using UTF-8. This
code is simply completely flawed. The [] operator refers to bytes of
the string, so you are only taking the first byte of the string and
assigning it to the text of the TEdit, which obviously only works for
single byte characters, but UTF-8 chars usually have 1, 2 or 3 bytes.

I suggest that you read more on UTF-8: http://en.wikipedia.org/wiki/UTF-8

-- 
Felipe Monteiro de Carvalho




More information about the Lazarus mailing list