[Lazarus] Problems with accented characters

Silvio Clecio silvioprog at gmail.com
Mon Mar 8 01:09:18 CET 2010


Hellow JoshyFun,

JoshyFun escreveu:
> So your problem is that UTF8Key is not "realtime" modificable as "Key"
> in KeyPress event ?
> 
> As UTF8Key appears as "var" parameter it looks like a bug to me.

Yes. For me too. And here em my PC, OnKeyPress works normal only for
Windows (XP). :(

> Meanwhile you can use KeyPress to perform the task converting key to
> UTF8, perform the changes needed and them convert back to ansi mode.
> This way when UTF8KeyPress accepts changed UTF8Key (if it should do
> it) you should simply change the routine position and remove the 2
> conversion lines.
> 

In a very simple test, I'm trying this:

[code]
const
  CWithAccent: array [0..46] of string = ('à', 'á', 'â', 'ã', 'ä', 'è', 'é',
    'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú',
'û', 'ü',
    'À', 'Á', 'Â', 'Ã', 'Ä', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ò',
'Ó', 'Ô',
    'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'ç', 'Ç', 'ñ', 'Ñ');
  CWithoutAccent: array [0..46] of string = ('a', 'a', 'a', 'a', 'a',
'e', 'e',
    'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'u', 'u',
'u', 'u',
    'A', 'A', 'A', 'A', 'A', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'O',
'O', 'O',
    'O', 'O', 'U', 'U', 'U', 'U', 'c', 'C', 'n', 'N');

uses
  StrUtils;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
begin
  Key := StringsReplace(AnsiToUtf8(Key), CWithAccent, CWithoutAccent,
[rfReplaceAll])[1];
end;
[/code]
(Please, see well here: http://pastebin.com/qmu80j74)

But unfortunately is working only on Windows. :(

-- 
[]'s

Silvio Clécio
--
programmer ObjectPascal - Blog: http://blog.silvioprog.com.br
programmer ObjectPascal - Site: http://www.silvioprog.com.br
programmer ObjectPascal - Twitter: http://twitter.com/silvioprog
--
grupo Lazarus-BR no Google - http://groups.google.com/group/lazarus-br/
--
Mensagem assinada com PGP Public Key, Ver.: GnuPG v1.4.9 (GNU/Linux)




More information about the Lazarus mailing list