PathDelim VS DirectorySeparatorChar
Asked Answered
A

2

8

One can use either

  • System.IOUtils.TPath.DirectorySeparatorChar

http://docwiki.embarcadero.com/Libraries/Seattle/en/System.IOUtils.TPath.DirectorySeparatorChar

OR

  • System.SysUtils.PathDelim

Are there any particular differences, benefits using one over another part from System.IOUtils.TPath is more object oriented interface?

http://docwiki.embarcadero.com/Libraries/Seattle/en/System.SysUtils

Adriell answered 21/11, 2016 at 8:37 Comment(2)
It depends if you want to target multiple platforms. PathDelim seems to be limited to Windows while TPath is valid for all OS.Mummer
@Mummer No, PathDelim supports all platformsMicrocyte
M
10

System.SysUtils.PathDelim was introduced in Delphi 6 / Kylix 1, as a means to enable the writing of platform independent code. The introduction of Kylix, the original Delphi Linux compiler, meant that for the first time Delphi code executed on a *nix platform, as well as its original target of Windows.

System.IOUtils.TPath.DirectorySeparatorChar is part of the IOUtils unit that was introduced more recently to support the current wave of cross-platform tooling, which supports MacOS, iOS, Android and will soon encompass Linux once more.

Where you have a choice between System.SysUtils and System.IOUtils, you are generally expected to use the latter. The System.IOUtils is the cross-platform unit for file system support. That said, you commonly would not use DirectorySeparatorChar directly, but instead would use methods like System.IOUtils.TPath.Combine.

Microcyte answered 21/11, 2016 at 9:7 Comment(0)
V
3

TPath.DirectorySeparatorChar is defined in System.IOUtils as

{$IFDEF MSWINDOWS}
  FDirectorySeparatorChar := '\';    // DO NOT LOCALIZE;
  // ...
{$ENDIF}
{$IFDEF POSIX}
  FDirectorySeparatorChar := '/';    // DO NOT LOCALIZE;
  // ...
{$ENDIF}

while PathDelim is defined in System.SysUtils as

PathDelim  = {$IFDEF MSWINDOWS} '\'; {$ELSE} '/'; {$ENDIF}

While the conditionals are slightly different, they would only differ if neither or both of MSWINDOWS and POSIX were defined, which is not the case for any platform. And if there would be such a platform in the future, the declarations would surely be fixed accordingly.

TL;DR: There is no difference, you can use either based on your preference.

Vintager answered 21/11, 2016 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.