Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
 
Delphi 12 Athens
 
#14

Re: [TFileStream] Widestring Dateinamen

  Alt 2. Mär 2009, 17:33
OK, dann noch ohne die ...Ex-Strings
Delphi-Quellcode:
// UnicodeFileStream.pas

Unit UnicodeFileStream;

Interface
  Uses {$IF CompilerVersion >= 14.0}RTLConsts{$ELSE}Consts{$IFEND}, Windows, SysUtils, Classes;

  Type TFileStreamX = Class(TFileStream)
    Public
      Constructor Create(Const FileName: WideString; Mode: Word); Overload;
      Constructor Create(Const FileName: WideString; Mode: Word; Rights: Cardinal); Overload;
      Destructor Destroy; Override;
    End;

Implementation
  Constructor TFileStreamX.Create(Const FileName: WideString; Mode: Word);
    Begin
      Create(Filename, Mode, 0);
    End;

  Constructor TFileStreamX.Create(Const FileName: WideString; Mode: Word; Rights: Cardinal);
    Const AccessMode: Array[0..2] of LongWord = (GENERIC_READ, GENERIC_WRITE, GENERIC_READ or GENERIC_WRITE);
      ShareMode: Array[0..4] of LongWord = (0, 0, FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE);

    Begin
      If Mode = fmCreate Then Begin
        Inherited Create(CreateFileW(PWideChar(FileName), GENERIC_READ or GENERIC_WRITE,
          0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0));
        If FHandle < 0 Then
          Raise EFCreateError.CreateFmt(SFCreateError, [ExpandFileName(FileName)]);
      End Else Begin
        If ((Mode and 3) <= fmOpenReadWrite) and ((Mode and $F0) <= fmShareDenyNone) Then Begin
          Inherited Create(CreateFileW(PWideChar(FileName), AccessMode[Mode and 3],
            ShareMode[(Mode and $F0) shr 4], nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0));
        End Else Inherited Create(0);
        If FHandle < 0 Then
          Raise EFOpenError.CreateFmt(SFOpenError, [ExpandFileName(FileName)]);
      end;
    End;

  Destructor TFileStreamX.Destroy;
    Begin
      If FHandle >= 0 Then FileClose(FHandle);
      Inherited Destroy;
    End;

End.
falls des mit den CONDITIONALEXPRESSIONS ( {$IF ...} ) in der DelphiVersion noch nicht klappt, dann sag Bescheid.

bzw. hast du die JEDI's installiert?
$2B or not $2B
  Mit Zitat antworten Zitat