THRIFT-3788 Compatibility improvements and Win64 support
Client: Delphi
Patch: Jens Geyer
Revised previous patch.
diff --git a/lib/delphi/src/Thrift.Stream.pas b/lib/delphi/src/Thrift.Stream.pas
index d78afe6..7c448d8 100644
--- a/lib/delphi/src/Thrift.Stream.pas
+++ b/lib/delphi/src/Thrift.Stream.pas
@@ -19,9 +19,7 @@
unit Thrift.Stream;
-{$IF CompilerVersion >= 23.0}
- {$LEGACYIFEND ON}
-{$IFEND}
+{$I Thrift.Defines.inc}
interface
@@ -30,11 +28,11 @@
SysUtils,
SysConst,
RTLConsts,
- {$IF CompilerVersion < 23.0}
- ActiveX,
+ {$IFDEF OLD_UNIT_NAMES}
+ ActiveX,
{$ELSE}
- Winapi.ActiveX,
- {$IFEND}
+ Winapi.ActiveX,
+ {$ENDIF}
Thrift.Utils;
type
@@ -112,10 +110,8 @@
procedure TThriftStreamAdapterCOM.Flush;
begin
- if IsOpen then
- begin
- if FStream <> nil then
- begin
+ if IsOpen then begin
+ if FStream <> nil then begin
FStream.Commit( STGC_DEFAULT );
end;
end;
@@ -128,17 +124,15 @@
procedure TThriftStreamAdapterCOM.Open;
begin
-
+ // nothing to do
end;
function TThriftStreamAdapterCOM.Read( var buffer: TBytes; offset: Integer; count: Integer): Integer;
begin
inherited;
Result := 0;
- if FStream <> nil then
- begin
- if count > 0 then
- begin
+ if FStream <> nil then begin
+ if count > 0 then begin
FStream.Read( @buffer[offset], count, @Result);
end;
end;
@@ -153,34 +147,27 @@
begin
FillChar( statstg, SizeOf( statstg), 0);
len := 0;
- if IsOpen then
- begin
- if Succeeded( FStream.Stat( statstg, STATFLAG_NONAME )) then
- begin
+ if IsOpen then begin
+ if Succeeded( FStream.Stat( statstg, STATFLAG_NONAME )) then begin
len := statstg.cbSize;
end;
end;
SetLength( Result, len );
- if len > 0 then
- begin
- if Succeeded( FStream.Seek( 0, STREAM_SEEK_SET, NewPos) ) then
- begin
+ if len > 0 then begin
+ if Succeeded( FStream.Seek( 0, STREAM_SEEK_SET, NewPos) ) then begin
FStream.Read( @Result[0], len, @cbRead);
end;
end;
end;
procedure TThriftStreamAdapterCOM.Write( const buffer: TBytes; offset: Integer; count: Integer);
-var
- nWritten : Integer;
+var nWritten : Integer;
begin
inherited;
- if IsOpen then
- begin
- if count > 0 then
- begin
+ if IsOpen then begin
+ if count > 0 then begin
FStream.Write( @buffer[0], count, @nWritten);
end;
end;
@@ -193,22 +180,18 @@
var
len : Integer;
begin
- if count > 0 then
- begin
+ if count > 0 then begin
len := Length( buffer );
- if (offset < 0) or ( offset >= len) then
- begin
+ if (offset < 0) or ( offset >= len) then begin
raise ERangeError.Create( SBitsIndexError );
end;
- if count > len then
- begin
+ if count > len then begin
raise ERangeError.Create( SBitsIndexError );
end;
end;
end;
-function TThriftStreamImpl.Read(var buffer: TBytes; offset,
- count: Integer): Integer;
+function TThriftStreamImpl.Read(var buffer: TBytes; offset, count: Integer): Integer;
begin
Result := 0;
CheckSizeAndOffset( buffer, offset, count );
@@ -237,16 +220,15 @@
destructor TThriftStreamAdapterDelphi.Destroy;
begin
- if FOwnsStream then
- begin
- FStream.Free;
- end;
+ if FOwnsStream
+ then Close;
+
inherited;
end;
procedure TThriftStreamAdapterDelphi.Flush;
begin
-
+ // nothing to do
end;
function TThriftStreamAdapterDelphi.IsOpen: Boolean;
@@ -256,7 +238,7 @@
procedure TThriftStreamAdapterDelphi.Open;
begin
-
+ // nothing to do
end;
function TThriftStreamAdapterDelphi.Read(var buffer: TBytes; offset,
@@ -264,8 +246,7 @@
begin
inherited;
Result := 0;
- if count > 0 then
- begin
+ if count > 0 then begin
Result := FStream.Read( Pointer(@buffer[offset])^, count)
end;
end;
@@ -299,8 +280,7 @@
count: Integer);
begin
inherited;
- if count > 0 then
- begin
+ if count > 0 then begin
FStream.Write( Pointer(@buffer[offset])^, count)
end;
end;