View Issue Details

IDProjectCategoryView StatusLast Update
0010850LazarusDebuggerpublic2014-01-11 01:37
ReporterVladimir ZhirovAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version0.9.24Product Build 
Target Version1.2.0Fixed in Version1.2.0 
Summary0010850: Encoding of locale-specific characters in GetAppConfigDir(False) result
DescriptionUnder Windows, the result of GetAppConfigDir(False) is normally:
C:\Documents and Settings\<ProfileName>\Local Settings\Application Data\appname\

When launching the project from Lazarus by F9 the encoding of locale-specific characters in <ProfileName> is different from one that is returned when launching the executable from any file manager.

The example:

1) When launching the project from Lazarus bu F9:
C:\Documents and Settings\‚« ¤Ё¬Ёа\Local Settings\Application Data\project1
Locale-specific characters seem to be encoded in CP 866

2) When launching the executable from file manager:
C:\Documents and Settings\Владимир\Local Settings\Application Data\project1
Locale-specific characters seem to be encoded in CP 1251
Additional InformationTest project source code:

program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  crt, Sysutils
  { you can add units after this };

var
  dir: string;
  sl: TStringList;
begin
  dir := GetAppConfigDir(false);
  sl := TStringList.Create;
  sl.Text := dir;
  sl.SaveToFile('dir.txt');
  sl.Free;
end.
TagsNo tags attached.
Fixed in Revisionr43495, r43692
LazTarget1.2
WidgetsetWin32/Win64
Attached Files

Activities

Vincent Snijders

2008-03-05 07:21

manager   ~0018145

Do you launch Lazarus from the file manager too?

Boguslaw Brandys

2008-03-05 17:49

developer   ~0018172

Test it that way:

run you program directly clicking on it from explorer
then test running it invoked from cmd.exe shell

Results ?

I've found that this function is using pointer to SHGetFolderPathA and two libs are checked: first shell32.dll then shfolder.dll. That's a complication used to allow working on Win95/98/Me also I suppose.

I don't remember exactly but maybe command shell is a different subsystem in NT/2000/XP and so could have different code page set ???

That's why I asked to check from explorer and from cmd.exe shell

Vladimir Zhirov

2008-03-05 22:18

reporter   ~0018180

> Do you launch Lazarus from the file manager too?
Yes, I launch Lazarus from file manager by shortcut or by click on .lpr file

> Test it that way:
>
> run you program directly clicking on it from explorer
> then test running it invoked from cmd.exe shell
Results are correct (CP 1251) and the same both when running from explorer and cmd.exe.

> I don't remember exactly but maybe command shell is a different subsystem
> in NT/2000/XP and so could have different code page set ???
As far as I know, when using "writeln(somevar)" in console applications the output of command shell is always encoded in CP 866.

Vincent Snijders

2008-05-06 15:22

manager   ~0019251

Does the following program produce the same file:

program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  crt, Sysutils
  { you can add units after this };

var
  dir: string;
  sl: TStringList;
begin
  dir := AnsiToUtf8(GetAppConfigDir(false));
  sl := TStringList.Create;
  sl.Text := dir;
  sl.SaveToFile('dir.txt');
  sl.Free;
end.

Vincent Snijders

2008-06-04 11:15

manager   ~0019928

Caused by the fact that the debugger runs under a different codepage as when run directly. I don't know if we can fix the IDE, so that the debugger is running under the same codepage.

Bart Broersma

2013-11-28 19:41

developer   ~0071689

Use GetApConfigDirUTF8 instead.
It is now (r43495) implemented using WideString API's so it should be codepage independant.
(Only for NT based systems. The issue is not fixable for Win9x AFAICS.)

Martin Friebe

2014-01-10 19:45

manager   ~0072355

Last edited: 2014-01-10 19:58

View 2 revisions

This commit broke WinCe.

I "fixed" it (rev 43689) by copy and paste the old code into ifdefs.

However there seems other wince code in place. So there may now be duplicate code. I do not know if WinCe should/must/ could use the concept of the _functionFoo redirects ?

Please review, and apply a proper final fix if needed.

Bart Broersma

2014-01-11 01:31

developer   ~0072360

Last edited: 2014-01-11 01:36

View 2 revisions

I redefined the GetSpecialDirW for WinCE, based on the code in WinCe/SysUtils

{$IFDEF WINCE}
// In WinCE these API calls are in Windows unit
function GetWindowsSpecialDirW(ID : Integer) : String;
Var
  APath : Array[0..MAX_PATH] of WideChar;
  WS: WideString;
  Len: SizeInt;
begin
  Result := '';
  if SHGetSpecialFolderPath(0, APath, ID, True) then
  begin
    Len := StrLen(APath);
    SetLength(WS, Len);
    System.Move(APath[0], WS[1], Len * SizeOf(WideChar));
    Result := AppendPathDelim(Utf16ToUtf8(WS));
  end
  else
    Result:='';
end;
{$ELSE}

I am unable to compile for WinCE, so can you please test r43692?

Issue History

Date Modified Username Field Change
2008-02-18 10:19 Vladimir Zhirov New Issue
2008-02-18 10:19 Vladimir Zhirov Widgetset => Win32
2008-03-04 13:35 Vincent Snijders Project Lazarus => FPC
2008-03-04 23:57 Peter Vreman Project FPC => Lazarus
2008-03-05 07:21 Vincent Snijders LazTarget => 1.0
2008-03-05 07:21 Vincent Snijders Note Added: 0018145
2008-03-05 07:21 Vincent Snijders Status new => feedback
2008-03-05 17:49 Boguslaw Brandys Note Added: 0018172
2008-03-05 22:18 Vladimir Zhirov Note Added: 0018180
2008-04-24 09:57 Vincent Snijders Target Version => 1.0.0
2008-05-06 15:22 Vincent Snijders Note Added: 0019251
2008-06-04 11:14 Vincent Snijders Status feedback => acknowledged
2008-06-04 11:15 Vincent Snijders Note Added: 0019928
2008-06-04 11:15 Vincent Snijders Category IDE => Debugger
2008-06-04 11:15 Vincent Snijders Description Updated
2011-12-18 10:32 Vincent Snijders LazTarget 1.0 => 1.2
2011-12-18 10:32 Vincent Snijders Target Version 1.0.0 => 1.2.0
2013-11-28 19:41 Bart Broersma Fixed in Revision => r43495
2013-11-28 19:41 Bart Broersma Note Added: 0071689
2013-11-28 19:41 Bart Broersma Status acknowledged => resolved
2013-11-28 19:41 Bart Broersma Fixed in Version => 1.2.0
2013-11-28 19:41 Bart Broersma Resolution open => fixed
2013-11-28 19:41 Bart Broersma Assigned To => Bart Broersma
2014-01-10 19:45 Martin Friebe Note Added: 0072355
2014-01-10 19:45 Martin Friebe Status resolved => assigned
2014-01-10 19:45 Martin Friebe Resolution fixed => reopened
2014-01-10 19:58 Martin Friebe Note Edited: 0072355 View Revisions
2014-01-11 01:31 Bart Broersma Note Added: 0072360
2014-01-11 01:36 Bart Broersma Note Edited: 0072360 View Revisions
2014-01-11 01:37 Bart Broersma Fixed in Revision r43495 => r43495, r43692
2014-01-11 01:37 Bart Broersma Status assigned => resolved
2014-01-11 01:37 Bart Broersma Resolution reopened => fixed