Author Topic: FileExists is always False when using german umlauts on Windows CE  (Read 2958 times)

DRIGUS

  • Jr. Member
  • **
  • Posts: 64
Lazarus 4.8
FPC 3.2.2

FileExists seems to be always False if you use an Unicode string filename with german umlauts on Windows CE and mode DELPHIUNICODE. I tracked it down to the following function in sysutils.pp:

Code: Pascal  [Select][+][-]
  1. Function FileGetAttr (Const FileName : UnicodeString) : Longint;
  2. var
  3.   fn: PWideChar;
  4. begin
  5.   fn:=StringToPWideChar(FileName);
  6.   Result:=GetFileAttributes(fn);
  7.   FreeMem(fn);
  8. end;
  9.  

  The problem seems to be StringToPWideChar and the not necessary Unicode to ANSI conversion.
« Last Edit: August 19, 2026, 04:40:47 pm by DRIGUS »
DRIGUS GmbH

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: FileExists is always False when using german umlauts on Windows CE
« Reply #1 on: August 19, 2026, 07:46:25 pm »
Test with fpc main, and if the bug is still there, file a bugreport in the fpc bugtracker.

Bart

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1607
    • Lebeau Software
Re: FileExists is always False when using german umlauts on Windows CE
« Reply #2 on: August 19, 2026, 08:41:00 pm »
The problem seems to be StringToPWideChar and the not necessary Unicode to ANSI conversion.

I would have just used this instead:

Code: Pascal  [Select][+][-]
  1. Function FileGetAttr (Const FileName : UnicodeString) : Longint;
  2. begin
  3.   Result:=GetFileAttributesW(PWideChar(FileName));
  4. end;
  5.  
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

DRIGUS

  • Jr. Member
  • **
  • Posts: 64
Re: FileExists is always False when using german umlauts on Windows CE
« Reply #3 on: August 20, 2026, 08:37:58 am »
Code: Pascal  [Select][+][-]
  1. Function FileGetAttr (Const FileName : UnicodeString) : Longint;
  2. begin
  3.   Result:=GetFileAttributesW(PWideChar(FileName));
  4. end;
  5.  

This is what I have tested to fix the problem temporary. And it is already used in FileSetAttr:

Code: Pascal  [Select][+][-]
  1. Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
  2. begin
  3.   if not SetFileAttributes(PWideChar(FileName), Attr) then
  4.     Result := GetLastError
  5.   else
  6.     Result:=0;
  7. end;
  8.  

  I took a look at fpc main and the source for FileGetAttr is still the same. And it also should affect DirectoryExists. I will build a test case and file a bugreport.
  Edit: https://gitlab.com/freepascal.org/fpc/source/-/work_items/41858

  How can I bypass the bug until a Lazarus release will have a fix? Is it sufficient to place a modified copy of sysutils.pp in the source search path?
« Last Edit: August 20, 2026, 01:18:36 pm by DRIGUS »
DRIGUS GmbH

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: FileExists is always False when using german umlauts on Windows CE
« Reply #4 on: August 20, 2026, 10:11:15 pm »
Basically you can only correct it for code you call yourself (just correct the code and put it in a unit of your own).
However, any place where an fpc unit calls it, it'll call the bugged implementation.

For a more thorough sulution yYou can fix the code in fpc main, build fpc and build the cross compiler for wince and install that home-brew version.

Bart


Thaddy

  • Hero Member
  • *****
  • Posts: 19805
  • Glad to be alive.
Re: FileExists is always False when using german umlauts on Windows CE
« Reply #6 on: August 21, 2026, 07:15:27 am »
And added to 3.2.4 candidate too it seems. At least marked as a back-port candidate.
« Last Edit: August 21, 2026, 07:18:17 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

 

TinyPortal © 2005-2018