View Issue Details

IDProjectCategoryView StatusLast Update
0024843LazarusDatabasepublic2014-03-10 11:26
ReporterminimusAssigned ToBigChimp 
Status resolvedResolutionno change required 
PlatformOSWin32OS VersionXP
Product VersionProduct Build 
Target VersionFixed in Version 
Summary0024843: Code issue in functions TWideStringField GetAsString & SetAsString
DescriptionMissing conversion UTF8String <--> UnicodeString.
If it was supposed automatic conversion, it does not work.

//=== original =====================

function TWideStringField.GetAsString: string;
  Result := GetAsWideString;

procedure TWideStringField.SetAsString(const aValue: string);

//=== correct code =====================

function TWideStringField.GetAsString: string;
  Result := UTF8Encode(GetAsWideString);

procedure TWideStringField.SetAsString(const aValue: string);
TagsNo tags attached.
Fixed in Revision
Attached Files


related to 0012206 resolvedLacaK FPC ODBC Query in DBGrid, some Cells are Empty (Encoding) 


Jonas Maebe

2013-08-08 15:31

manager   ~0069296

Those functions are declared as setting/returning ansistrings, not as setting/returning UTF-8 strings. What you are asking for would be extra methods called GetAsUtf8String and SetAsUtf8String or so.


2013-08-08 15:43

reporter   ~0069297

Last edited: 2013-08-08 16:04

View 2 revisions

Visual controls used GetDisplayText -> GetText -> GetAsString :(

IMHO, all methods should use UTF8 string only (important unambiguous interpretation of programmer; code of visual components remains in its original state). To retrieve the value in native format, there is a corresponding method: GetData.

If the same variable of type string may contain a different character encoding is a programmer's nightmare. Together with the automatic conversion of a double nightmare. :(

Jonas Maebe

2013-08-08 15:48

manager   ~0069298

That's a Lazarus issue.


2013-08-12 07:30

developer   ~0069344

This kind of reports appears periodicaly ;-) (see for example 0012206)
(I was also confused with this when I came to using Lazarus/FPC)
General answer in this case is, that TField (part of FCL) is "character encoding agnostic". It means, that user may request other encoding than UTF8 (which is expected by LCL - Lazarus).
So when you work with Lazarus you must setup connection (TSQLConnection) to use "connection encoding"=UTF8 . In this case you will retrieve from database character data encoded in UTF8 and they will be properly displayed in Lazarus DB-aware controls.

Reinier Olislagers

2014-03-10 11:26

developer   ~0073590

See Lacak's remark. If wanted, reporter could update the Lazarus wiki with the relevant information, as this is currently a documentation issue.

Issue History

Date Modified Username Field Change
2013-08-08 15:15 minimus New Issue
2013-08-08 15:31 Jonas Maebe Note Added: 0069296
2013-08-08 15:31 Jonas Maebe Severity minor => feature
2013-08-08 15:31 Jonas Maebe Category FCL => Database
2013-08-08 15:43 minimus Note Added: 0069297
2013-08-08 15:48 Jonas Maebe Note Added: 0069298
2013-08-08 15:48 Jonas Maebe Project FPC => Lazarus
2013-08-08 16:04 minimus Note Edited: 0069297 View Revisions
2013-08-12 07:30 LacaK Note Added: 0069344
2013-08-12 23:03 Juha Manninen Relationship added related to 0012206
2014-03-10 11:26 Reinier Olislagers LazTarget => -
2014-03-10 11:26 Reinier Olislagers Note Added: 0073590
2014-03-10 11:26 Reinier Olislagers Status new => resolved
2014-03-10 11:26 Reinier Olislagers Resolution open => no change required
2014-03-10 11:26 Reinier Olislagers Assigned To => Reinier Olislagers