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;