Recent

Author Topic: Which string type for a directory?  (Read 1884 times)

dietmar

  • Full Member
  • ***
  • Posts: 170
Which string type for a directory?
« on: September 07, 2021, 06:37:07 pm »
Hello,

I want to save a directory name in a string variable, the directory is chosen via SelectDirectoryDialog. There, Filename seems to be a normal string. Is that ok even for possible directory names in foreign languages with special characters, or what should I use here?

Thx,
--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

Bart

  • Hero Member
  • *****
  • Posts: 4502
    • Bart en Mariska's Webstek
Re: Which string type for a directory?
« Reply #1 on: September 07, 2021, 06:44:24 pm »
You're on Lazarus.
Just use String, not any other kind like UTF8String or RawByteString.
You'll be fine with whatever you want to do with that string then, it will work in all file routines (like createfile) and things like TStrings.LoadFromFile etc.

By default String is encoded as UTF8, and before passing it to the API's that handle files, it will be converted to UnicodeString/WideString on Windows at leats (*nix tends to use UTF8), so there will be no loss of information.

Bart

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Which string type for a directory?
« Reply #2 on: September 07, 2021, 07:05:22 pm »
Fantastic, thank you!

--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

 

TinyPortal © 2005-2018