After a MySQL query I have a dynamic array containing the results. Both database and the Lazarus app are in UTF-8 encoded. I want to show the results in a Memo with fixed size font (Consolas).
clArray is defined as: "Array of Array of String"
I am using the following procedure:
line: String;
...
for iRow := 0 to High(clArray) do begin
line := Format('%-2d', [iRow+1]) + '|';
for iCol := 0 to High(clArray[iRow]) do begin
if iCol = 0 then line += Format('%0:-6s', [clArray[iRow, iCol]]) + '|'
else line += Format('%0:-17s', [clArray[iRow, iCol]]) + '|' + ' ---> String length: ' +
IntToStr(Length(clArray[iRow, iCol]));
end;
Memo1.Append(line);
end;
The result of the format function shows a problem with accented characters. The string containing the char "è" (c3a8) takes 2 bytes, so it’s longer,
that's means that we are really in UTF-8
1 |3882 |Bernex | ---> String length: 6
2 |125527|Carouge GE | ---> String length: 10
3 |125527|Genèève | ---> String length: 9
4 |162175|Geneve | ---> String length: 6
5 |84493 |Genève | ---> String length: 7
6 |254782|Hermance | ---> String length: 8
7 |103866|Mont Saxonnex | ---> String length: 13
8 |103865|Mont Saxonnex | ---> String length: 13
9 |185163|Prevessin Moens | ---> String length: 15
10|212913|Prevessin Moens | ---> String length: 15
Why text with accented char are not aligned ? What did I wrong ?