- { TFileStream class }
- TFileStream = class(THandleStream)
- public
- constructor Create(const FileName: string; Mode: Word); overload;
- constructor Create(const FileName: string; Mode: Word; Rights: Cardinal); overload;
- destructor Destroy; override;
- end;
- { TFileStream }
- constructor TFileStream.Create(const FileName: string; Mode: Word);
- begin
- {$IFDEF MSWINDOWS}
- Create(Filename, Mode, 0);
- {$ELSE}
- Create(Filename, Mode, FileAccessRights);
- {$ENDIF}
- end;
- constructor TFileStream.Create(const FileName: string; Mode: Word; Rights: Cardinal);
- begin
- if Mode = fmCreate then
- begin
- inherited Create(FileCreate(FileName, Rights));
- if FHandle < 0 then
- raise EFCreateError.CreateResFmt(@SFCreateErrorEx, [ExpandFileName(FileName), SysErrorMessage(GetLastError)]);
- end
- else
- begin
- inherited Create(FileOpen(FileName, Mode));
- if FHandle < 0 then
- raise EFOpenError.CreateResFmt(@SFOpenErrorEx, [ExpandFileName(FileName), SysErrorMessage(GetLastError)]);
- end;
- end;
- destructor TFileStream.Destroy;
- begin
- if FHandle >= 0 then FileClose(FHandle);
- inherited Destroy;
- end;
VCL类学习之(十) TFileStream
最新推荐文章于 2017-08-23 21:09:23 发布