Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-01

Problem encode UTF8 with BOM in unit

9 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Zaher Dirkey

Hi,

I created new project, then choose "File Settings -> Encoding -> UTF8 with BOM -> Change file"

Added new listbox1 to the form, in source code (button ) i added some items with my local language, this language in run time apear like "??????".

Is that a bug or i missed something?

The project is attached.

I am using Lazarus 0.9.31 r FPC 2.6.0 i386-win32-win32/win64

Thanks in advance.

Best Regards
Zaher Dirkey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120125/d003decc/attachment.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: utfbom.zip
Type: application/zip
Size: 2687 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120125/d003decc/attachment.zip>

Reply by email

Mattias Gaertner
to Zaher Dirkey
Show quoted text 9 lines
Hi, I created new project, then choose "File Settings -> Encoding -> UTF8 with BOM -> Change file" Added new listbox1 to the form, in source code (button ) i added some items with my local language, this language in run time apear like "??????". Is that a bug or i missed something?

When the compiler sees the UTF8-BOM it translates all strings to your system encoding, which is not UTF-8. The LCL expects UTF-8 strings. Result: you see only garbage.

Mattias

Reply by email

Zaher Dirkey
to Mattias Gaertner

On Wed, Jan 25, 2012 at 1:33 AM, Mattias Gaertner <

Show quoted text 25 lines
wrote: On Wed, 25 Jan 2012 00:02:07 +0200 Zaher Dirkey wrote: > Hi, > > I created new project, then choose "File Settings -> Encoding -> UTF8 with > BOM -> Change file" > > Added new listbox1 to the form, in source code (button ) i added some items > with my local language, this language in run time apear like "??????". > > Is that a bug or i missed something? When the compiler sees the UTF8-BOM it translates all strings to your system encoding, which is not UTF-8. The LCL expects UTF-8 strings. Result: you see only garbage. Mattias

How can i resolve this problem, because i share this unit with Delphi 2007, Delphi 2007 not understand UTF8 *without *BOM

Thanks

Zaher Dirkey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120125/4a6dc04e/attachment.html>

Reply by email

Felipe Monteiro de Carvalho
to Zaher Dirkey

2012/1/25 Zaher Dirkey :

How can i resolve this problem, because i share this unit with Delphi 2007, Delphi 2007 not understand UTF8 without BOM

For FPC up to 2.6 you can use all text fields as ansistring variables and use ifdefs to call a procedure to convert all UTF-8 strings to Ansi only in Delphi, see this unit from the Magnifier which does exactly this:

http://magnifier.svn.sourceforge.net/viewvc/magnifier/trunk/translationsvmg.pas?revision=210&view=markup
See there procedure TTranslations.UpdateTranslations;

If you are using FPC 2.7 try keeping the BOM and add this call before Application.Initialize:

SetMultiByteConversionCodePage(CP_UTF8);
Felipe Monteiro de Carvalho

Reply by email

Honza
to Zaher Dirkey: I created new project, then choose "File Settings -> Encoding -> UTF8 with BOM -> Change…

2012/1/24 Zaher Dirkey :

I created new project, then choose "File Settings -> Encoding -> UTF8 with BOM -> Change file"

Although BOM is valid in UTF8, its use is not recommended (http://en.wikipedia.org/wiki/Byte_order_mark#cite_note-1). I'm surprised Lazarus supports this feature should be removed and UTF-8 files with BOM should be rejected by FPC and Lazarus as invalid.

Flame war in 3, 2, ... ;-)

Reply by email

José Mejuto
to Honza

Hello Lazarus-List,

Wednesday, January 25, 2012, 11:13:16 AM, you wrote:

H> Although BOM is valid in UTF8, its use is not recommended H> (http://en.wikipedia.org/wiki/Byte_order_mark#cite_note-1). I'm H> surprised Lazarus supports this feature should be H> removed and UTF-8 files with BOM should be rejected by FPC and Lazarus H> as invalid.

Please, re-read the cite. It should be used in undetermined encoding protocol media, like files, in fact it is quite mandatory in many of them. The cite is about setting a BOM in things like string variables where the protocol is expected (programatically) or database fields where the field definition already states the encoding used.

A pascal program file without BOM is ansi as you can say that a file could not be UTF8 but you can not say that it is not ansi unless BOM is present.

Best regards, Jos?

Reply by email

Maxim Ganetsky
to Zaher Dirkey: I created new project, then choose "File Settings -> Encoding -> UTF8 with BOM -> Change…

25.01.2012 2:02, Zaher Dirkey ?????:

Show quoted text 9 lines
Hi, I created new project, then choose "File Settings -> Encoding -> UTF8 with BOM -> Change file" Added new listbox1 to the form, in source code (button ) i added some items with my local language, this language in run time apear like "??????". Is that a bug or i missed something?

When BOM or {$codepage utf8} directive is present compiler converts your strings to widestrings. So you have two options

1. Add {$codepage 8859-1} directive at the start of the .pas file.

2. Use UTF8Encode() function, e.g.

ListBox1.Items.Add(UTF8Encode('?????? ?????'));
Best regards, Maxim Ganetsky mailto:

Reply by email

Maxim Ganetsky
to Zaher Dirkey

26.01.2012 1:57, Zaher Dirkey ?????:

Show quoted text 15 lines
On Wed, Jan 25, 2012 at 10:47 PM, Maxim Ganetsky < <mailto:>> wrote: {$codepage 8859-1} Thanks, Until now this sloved my problem in both Delphi and Lazarus {$ifdef FPC} {$mode delphi} {$codepage 8859-1} {$endif} But strange, it is not as expected!.

No, it works exactly as documented:

http://wiki.lazarus.freepascal.org/LCL_Unicode_Support#Free_Pascal_Particularities

http://wiki.freepascal.org/Language_related_articles#UTF-8_support

Best regards, Maxim Ganetsky mailto:

Reply by email