Thema: Delphi Bug

Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#6

AW: Delphi Bug

  Alt 21. Feb 2014, 19:57
Da du ja XE5 hast, kannst du natürlich auch folgende "Schweinerei" benutzen:
Delphi-Quellcode:
uses
  Custom.Types;

const
  INIFILE_NAME : TFilePath = '%ProgramData%\Lukas\Test.ini';


LIni := TIniFile.Create( INIFILE_NAME.Expand );
benötigt wird dazu das hier
Delphi-Quellcode:
unit Custom.Types;

interface

type
  TFilePath = type string;

  TFilePathHelper = record helper for TFilePath
    function Expand : TFilePath;
    function Exists( FollowLink : Boolean = True ) : Boolean;
    function GetDirectoryName : string;
    function GetFileName : string;
    function GetFileNameWithoutExtension : string;
    function GetFileExtension : string;
    function ForceDirectories : Boolean;
  end;

implementation

uses
  System.SysUtils,
  Winapi.Windows,
  System.IOUtils;

{ TFilePathHelper }

function TFilePathHelper.GetDirectoryName : string;
begin
  Result := TPath.GetDirectoryName( Self.Expand );
end;

function TFilePathHelper.GetFileExtension : string;
begin
  Result := TPath.GetExtension( Self.Expand );
end;

function TFilePathHelper.GetFileName : string;
begin
  Result := TPath.GetFileName( Self.Expand );
end;

function TFilePathHelper.GetFileNameWithoutExtension : string;
begin
  Result := TPath.GetFileNameWithoutExtension( Self.Expand );
end;

function TFilePathHelper.Exists( FollowLink : Boolean = True ) : Boolean;
begin
  Result := TFile.Exists( Self.Expand, FollowLink );
end;

function TFilePathHelper.Expand : TFilePath;
var
  LSize : Cardinal;
begin
  SetLength( Result, MAX_PATH + 1 );
  LSize := ExpandEnvironmentStrings( PChar( Self ), PChar( Result ), Length( Result ) );
  SetLength( Result, LSize - 1 );
end;

function TFilePathHelper.ForceDirectories : Boolean;
begin
  Result := System.SysUtils.ForceDirectories( Self.GetDirectoryName );
end;

end.
Ich überlasse es deiner Fantasie, was du da in den Helper noch so alles reinbauen möchtest ...
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat