基本概念: 关于const(13分)

  • 主题发起人 主题发起人 Celestial dog
  • 开始时间 开始时间
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 Max: Integer = 100;
In most cases, value must be a constant expression;
but if type is an array, record, procedural, or pointer type,
special rules apply.
这是delphi帮助里的原话!
很简单,我就不翻译了吧!

 
接受答案了.
 
后退
顶部