// 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.