把字节数组读入到流 - 回复 "巅枫" 的问题


问题来源: http://www.cnblogs.com/del/archive/2011/01/16/1936942.html#2012707
var {模拟三种字节数组}
  staticArr: array[0..6] of Byte = (65, 66, 67, 68, 69, 70, 71);
  dyanmicArr1: TBytes;
  dyanmicArr2: array of Byte;

procedure TForm1.Button1Click(Sender: TObject);
var
  stream: TMemoryStream;
begin
  stream := TMemoryStream.Create;
  stream.SetSize(SizeOf(staticArr));
  CopyMemory(stream.Memory, @staticArr, SizeOf(staticArr));
  stream.SaveToFile('C:\Temp\001.txt');
  stream.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  stream: TMemoryStream;
  i: Integer;
begin
  SetLength(dyanmicArr1, 7);
  for i := 0 to High(dyanmicArr1) do dyanmicArr1[i] := 65 + i;
  stream := TBytesStream.Create(dyanmicArr1);
  stream.SaveToFile('C:\Temp\002.txt');
  stream.Free;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  stream: TMemoryStream;
  i: Integer;
begin
  SetLength(dyanmicArr2, 7);
  for i := 0 to High(dyanmicArr2) do dyanmicArr2[i] := 65 + i;
  stream := TBytesStream.Create(TBytes(dyanmicArr2));
  stream.SaveToFile('C:\Temp\003.txt');
  stream.Free;
end;

你可能感兴趣的:(把字节数组读入到流 - 回复 "巅枫" 的问题)