* * *

Author Topic: 1.8.0RC5 - Raspberry Pi 3 Stretch - National characters not displayed correctly  (Read 419 times)

ertank

  • Full Member
  • ***
  • Posts: 147
Hello,

I used to have all national characters displayed and written to TextFile just fine. Now, I get problems as shown in attached pictures.
editor_code.png: How it is displayed in Lazarus source editor (and how I used to see it in running application when dialog displayed)
dialog.png: How I currently see it when displayed in running application.

I suspect something changed between SVN 56371 and SVN 56257 I started to have wrong displays of string literals. Variables seems to be OK. I am yet to try SVN 56257 back again. I shall report again if I can find something.

I confirm that there is no OS changes between above two SVN versions.

Anybody else having similar issues?

Thanks.
Ertan

ertank

  • Full Member
  • ***
  • Posts: 147
I confirm that it is not the SVN difference 1.8.0RC5 SVN: 56257 and SVN: 56371. Behaviour is same in both SVN versions.

It is using string literals or string variable what makes a difference. Below code display wrong characters:
Code: [Select]
begin
  ShowMessage('Dosya şifre çözme başarısız: ' + QuotedStr(ExtractFileName(TempString)));
end;

Where below code display correct characters:
Code: [Select]
var
  Test: string;
begin
      Test := 'Dosya şifre çözme başarısız: ';
      ShowMessage(Test + QuotedStr(ExtractFileName(TempString)));
end;

I could not understand what problem is here.

My fpc version is: Free Pascal Compiler version 3.0.4rc1 [2017/11/01] for arm (SVN: 37539)

Will report back when I do some more tests on 1.6.4 and 1.6.4 fixes branch.


ertank

  • Full Member
  • ***
  • Posts: 147
I have tried 1.6.4 SVN 56406 and result is same. If I assign string literals in a variable all is fine. Direct use of them is displayed wrongly in dialogs.

howardpc

  • Hero Member
  • *****
  • Posts: 2399
It looks as though the compiler encodes string literals by default with something other than UTF8.
Whereas variables declared as String in Lazarus are always UTF8 encoded (unless you go out of your way to change this).

GetMem

  • Hero Member
  • *****
  • Posts: 2417
I tested ShowMessage with you text and it works fine(see attachment). It looks like your source file is not UTF8 encoded. As an alternative solution you can use the following workaround:
Code: Pascal  [Select]
  1. function MessageDlgEx(const AMsg: string; ADlgType: TMsgDlgType;
  2.   AButtons: TMsgDlgButtons; AParent: TForm): TModalResult;
  3. var
  4.   MsgFrm: TForm;
  5. begin
  6.   MsgFrm := CreateMessageDialog(AMsg, ADlgType, AButtons);
  7.   try
  8.     MsgFrm.Position := poDefaultSizeOnly;
  9.     MsgFrm.FormStyle := fsSystemStayOnTop;
  10.     MsgFrm.Left := AParent.Left + (AParent.Width - MsgFrm.Width) div 2;
  11.     MsgFrm.Top := AParent.Top + (AParent.Height - MsgFrm.Height) div 2;
  12.     Result := MsgFrm.ShowModal;
  13.   finally
  14.     MsgFrm.Free
  15.   end;
  16. end;
  17.  
  18. procedure TForm1.Button1Click(Sender: TObject);
  19. begin
  20.   MessageDlgEx('Dosya şifre çözme başarısız: ', mtInformation, [mbOk], Form1);
  21. end;

Benefits:
1. Dialog will always be shown in the active form center
2. Dialog is always on top
3. Encoding works
4. Dialog icons(information, error, etc...)
« Last Edit: November 15, 2017, 06:28:21 am by GetMem »

ertank

  • Full Member
  • ***
  • Posts: 147
Hi GetMem,

Thanks for MessageDlgEx() example. I believe my source file is utf-8 encoded as below
Code: [Select]
pi@raspberrypi:~ $ file -bi uusb.pas
text/plain; charset=utf-8
pi@raspberrypi:~ $
I also have same problem with TextFile writes. When I open utf-8 encoded text file written by the application using string literals, I see national characters are not correct. Oddly enough, I dicovered that I have working portions of the application such as messages displayed from my data module seems to be fine.

I did not have such a problem before. I do not know if it is me constantly adding new forms and units which at some point making compiler to do odd things, or something completely different.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus