C
Celestial dog
Unregistered / Unconfirmed
GUEST, unregistred user!
摘自D5/demo
为什么这里可以用const,变量Data在过程里明明是变化的呀??
procedure TDataCompressor.DataOut(const Data: IDataBlock);
var
InStream, OutStream: TMemoryStream;
ZStream: TCompressionStream;
Size: Integer;
begin
InStream := TMemoryStream.Create;
try
{ Skip BytesReserved bytes of data }
InStream.Write(Pointer(Integer(Data.Memory) + Data.BytesReserved)^, Data.Size);
Size := InStream.Size;
OutStream := TMemoryStream.Create;
try
ZStream := TCompressionStream.Create(clFastest, OutStream);
try
ZStream.CopyFrom(InStream, 0);
finally
ZStream.Free;
end;
{ Clear the datablock, then write the compressed data back into the
datablock }
Data.Clear;
Data.Write(Size, SizeOf(Integer));
Data.Write(OutStream.Memory^, OutStream.Size);
finally
OutStream.Free;
end;
finally
InStream.Free;
end;
end;
为什么这里可以用const,变量Data在过程里明明是变化的呀??
procedure TDataCompressor.DataOut(const Data: IDataBlock);
var
InStream, OutStream: TMemoryStream;
ZStream: TCompressionStream;
Size: Integer;
begin
InStream := TMemoryStream.Create;
try
{ Skip BytesReserved bytes of data }
InStream.Write(Pointer(Integer(Data.Memory) + Data.BytesReserved)^, Data.Size);
Size := InStream.Size;
OutStream := TMemoryStream.Create;
try
ZStream := TCompressionStream.Create(clFastest, OutStream);
try
ZStream.CopyFrom(InStream, 0);
finally
ZStream.Free;
end;
{ Clear the datablock, then write the compressed data back into the
datablock }
Data.Clear;
Data.Write(Size, SizeOf(Integer));
Data.Write(OutStream.Memory^, OutStream.Size);
finally
OutStream.Free;
end;
finally
InStream.Free;
end;
end;