TMemoryStream 的 Position 变化后, 我曾经认为它的 Memory 属性也会变化; 只怪不看源码, 只想当然!
procedure TForm1.FormCreate(Sender: TObject); var Stream1,Stream2: TMemoryStream; pw: TPtrWrapper; begin Stream1 := TStringStream.Create('1234567890'); Stream2 := TStringStream.Create('ABCDEFGHIJ'); //想把 Stream1 变成 123DEFG890 pw := TPtrWrapper.Create(Stream2.Memory); pw := TPtrWrapper.Create(pw.ToInteger + 3); Stream1.Position := 3; Stream1.Write(pw.ToPointer^, 4); ShowMessage(TStringStream(Stream1).DataString); //123DEFG890 Stream1.Free; Stream2.Free; end;