fpspreadsheet: Introduce a TBufStream.Clear method and make the Size property read-only to avoid issues when setting Size to arbitrary values.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8930 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-03 20:33:22 +00:00
parent 477a3290f0
commit 186e9b86a3

View File

@ -30,7 +30,6 @@ type
function GetPosition: Int64; override; function GetPosition: Int64; override;
function GetSize: Int64; override; function GetSize: Int64; override;
class function IsWritingMode(AMode: Word): Boolean; class function IsWritingMode(AMode: Word): Boolean;
procedure SetSize64(const NewSize: Int64); override;
public public
constructor Create(AFileName: String; AMode: Word; constructor Create(AFileName: String; AMode: Word;
ABufSize: Cardinal = Cardinal(-1)); overload; ABufSize: Cardinal = Cardinal(-1)); overload;
@ -38,11 +37,13 @@ type
ABufSize: Cardinal = Cardinal(-1)); overload; ABufSize: Cardinal = Cardinal(-1)); overload;
constructor Create(ABufSize: Cardinal = Cardinal(-1)); overload; constructor Create(ABufSize: Cardinal = Cardinal(-1)); overload;
destructor Destroy; override; destructor Destroy; override;
procedure Clear;
procedure FillBuffer; procedure FillBuffer;
procedure FlushBuffer; procedure FlushBuffer;
function Read(var Buffer; Count: Longint): Longint; override; function Read(var Buffer; Count: Longint): Longint; override;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override; function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;
function Write(const ABuffer; ACount: Longint): Longint; override; function Write(const ABuffer; ACount: Longint): Longint; override;
property Size64: Int64 read GetSize;
end; end;
procedure ResetStream(var AStream: TStream); procedure ResetStream(var AStream: TStream);
@ -326,18 +327,14 @@ begin
FillBuffer; FillBuffer;
end; end;
procedure TBufStream.SetSize64(const NewSize: Int64); procedure TBufStream.Clear;
begin begin
if NewSize = 0 then FMemoryStream.Clear;
begin if not Assigned(FFileStream) then
FMemoryStream.Clear; CreateFileStream;
if not Assigned(FFileStream) then FFileStream.Size := 0;
CreateFileStream; FFileStream.Position := 0;
FFileStream.Size := 0; FFileStreamPos := 0;
FFileStream.Position := 0;
FFileStreamPos := 0;
end;
inherited;
end; end;
function TBufStream.Write(const ABuffer; ACount: LongInt): LongInt; function TBufStream.Write(const ABuffer; ACount: LongInt): LongInt;