Recent

Author Topic: Umlaut UTF-8 Question  (Read 3156 times)

guitarmang

  • New Member
  • *
  • Posts: 31
Umlaut UTF-8 Question
« on: April 16, 2018, 10:21:32 pm »
Hi All.
I'm stiil a newbie when it comes to any programming stuff, and it's been awhile.
A few years back, I created a Gui frontend for a couple cmd line tools (cdrecord and ddpinfo) using Lazarus 1.4.4

I recently updated to a new computer, and the latest version of Lazaurus.

Some of my older code for folder dialogs was e.g.
Code: Pascal  [Select][+][-]
  1.   if OpenCueDialog.Execute then
  2.   begin
  3.     opencuedialog.InitialDir := ddpdirdialog.FileName;
  4.     filename := UTF8ToSys(OpenCueDialog.Filename);
  5.     progressLogRichMemo.Text := systoutf8(filename + sLineBreak);
  6.   end;
  7. end;

If I have any folder names that contain german umlauts like ä ö ü ß, everything worked.

Now that I've updated, I removed all the UTF8ToSys, and systoutf8, as the new version of Lazarus gave me errors.

I have several folder dialogs in my gui, and now if a folder name has any of those umlauts, my program doesn't work.

I've tried to understand what's explained on the wiki, but I can't understand it.

Any help would greatly be appreciated.
Many Thanks,
Wyatt





totya

  • Hero Member
  • *****
  • Posts: 720
Re: Umlaut UTF-8 Question
« Reply #1 on: April 16, 2018, 11:28:50 pm »
Hi!

Works for me... Lazarus 1.8.2

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Memo1: TMemo;
  17.     OpenDialog1: TOpenDialog;
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. begin
  36.   if OpenDialog1.Execute then
  37.     Memo1.Lines.Add(OpenDialog1.FileName);
  38. end;
  39.  
  40. end.
  41.  

Result:

Quote
Memo1
C:\Tmp\ä ö ü ß\ä ö ü ß\ä ö ü ß.txt

I see your code, and don't like it for me this:

Code: Pascal  [Select][+][-]
  1. opencuedialog.InitialDir := ddpdirdialog.FileName;

because:

Code: Pascal  [Select][+][-]
  1. opencuedialog.InitialDir := ExtractFilePath(ddpdirdialog.FileName);

and so on... and then my question: cdrecord and ddpinfo cmdline utilities can use utf8 filename input?

guitarmang

  • New Member
  • *
  • Posts: 31
Re: Umlaut UTF-8 Question
« Reply #2 on: April 17, 2018, 12:37:25 am »
Hi totya.
Yeah, if I use ddpinfo cmdline utilities from a command prompt in window, it works fine, and recognizes the folder with the umlaut chars.

Edit.
All was working in Lazarus 1.4.4

Now it's not in 1.8.2

Thanks,
Wyatt
« Last Edit: April 17, 2018, 05:39:17 am by guitarmang »

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Umlaut UTF-8 Question
« Reply #3 on: April 17, 2018, 09:52:26 pm »
Hi!

As I said, I think you need to use the system codepage, and not the UTF8, for the external app parameters.

First, http://wiki.freepascal.org/Lazarus_with_FPC3.0_without_UTF-8_mode

From the link above, with this code, u can see your system codepage:

Code: Pascal  [Select][+][-]
  1.   Writeln('Console output codepage: ', GetTextCodePage(Output));
  2.   Writeln('System codepage: ', DefaultSystemCodePage);

For me, this is:

Quote
Console output codepage: 852
System codepage: 1250

With this information, this sample works for me (modified version v1.1)

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Memo1: TMemo;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. uses Process, LConvEncoding, LazUTF8, Windows;
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.Button1Click(Sender: TObject);
  36. var
  37.   s, s_from, s_to: string;
  38. begin
  39.   Memo1.Lines.Clear;
  40.  
  41.   Memo1.Lines.Add('System codepage: '+IntToStr(Windows.GetACP));
  42.  
  43.   // s_from:= 'c:\a\a.txt';
  44.   // s_to:=   'c:\a\b.txt';
  45.  
  46.   s_from:= 'c:\ä ö ü ß\ä ö ü ß.txt';
  47.   s_to:=   'c:\ä ö ü ß\ä ö ü ß_2.txt';
  48.  
  49.   // s_from:= 'c:\a\öüóőúéáűíÖÜÓŐÚÉÁŰÍ.txt';
  50.   // s_to:=   'c:\a\öüóőúéáűíÖÜÓŐÚÉÁŰÍ_2.txt';
  51.  
  52.   RunCommand('c:\windows\system32\cmd.exe',
  53.             ['/c',
  54.              'ECHO '+
  55.              AnsiQuotedStr(UTF8ToWinCP(s_from),'"')+
  56.              ' '+
  57.              AnsiQuotedStr(UTF8ToWinCP(s_to),'"')
  58.             ], s); Memo1.Lines.Add(CP852ToUTF8(s));
  59.  
  60.  
  61.   RunCommand('c:\windows\system32\cmd.exe',
  62.              ['/c',
  63.               'copy /b '+
  64.               AnsiQuotedStr(UTF8ToWinCP(s_from),'"')+
  65.               ' '+
  66.               AnsiQuotedStr(UTF8ToWinCP(s_to),'"')
  67.              ], s); Memo1.Lines.Add(CP852ToUTF8(s));
  68.  
  69. end;
  70.  
  71. end.

Output:

Quote
"c:\ä ö ü ß\ä ö ü ß.txt" "c:\ä ö ü ß\ä ö ü ß_2.txt"

        1 file(s) copied.


For example you original code:
Code: Pascal  [Select][+][-]
  1. if OpenCueDialog.Execute then
  2.   begin
  3.     opencuedialog.InitialDir := ddpdirdialog.FileName;
  4.     filename := UTF8ToSys(OpenCueDialog.Filename);
  5.     progressLogRichMemo.Text := systoutf8(filename + sLineBreak);
  6.   end;

need modify to (untested):
Code: Pascal  [Select][+][-]
  1. if OpenCueDialog.Execute then
  2.   begin
  3.     opencuedialog.InitialDir := ExtractFilePath(ddpdirdialog.FileName);
  4.     filename := UTF8ToWinCP(OpenCueDialog.Filename);
  5.     progressLogRichMemo.Text := WinCPToUTF8(filename) + sLineBreak;
  6.   end;
« Last Edit: April 17, 2018, 11:37:53 pm by totya »

guitarmang

  • New Member
  • *
  • Posts: 31
Re: Umlaut UTF-8 Question
« Reply #4 on: April 20, 2018, 01:27:44 am »
Hi totya.
Thanks again for the reply.

I've tried to get this going today.

I finally give up on it for now.

It's beyond my coding skills.

If I sent you a link to my full program, could you check it?

Many Thanks,
Wyatt


totya

  • Hero Member
  • *****
  • Posts: 720
Re: Umlaut UTF-8 Question
« Reply #5 on: April 20, 2018, 06:13:47 am »
If I sent you a link to my full program, could you check it?

Hi, okay... I will look it within few days.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Umlaut UTF-8 Question
« Reply #6 on: April 24, 2018, 05:40:09 pm »
So...?

 

TinyPortal © 2005-2018