如何合并两个 buffer(100分)

  • 主题发起人 主题发起人 let_it_be
  • 开始时间 开始时间
L

let_it_be

Unregistered / Unconfirmed
GUEST, unregistred user!
有两个 buffer, 怎样他们合并 未一个 (新的 buf= buf1 + buf2)<br>我这样写,为什么不成功?<br>procedure CombineBuffer(const Source1; const Source2; var Dest: pchar);<br>begin<br> &nbsp;move(Source1, pchar(integer(Dest))^, sizeof(Source1));<br> &nbsp;move(Source2, PChar(integer(Dest)+sizeof(Source1))^, sizeof(Source2));<br>end;
 
嗯,问题多多啊:<br>1、SizeOf 不能获取缓冲区大小,只能手工传入<br>2、返回的 Dest 缓冲区是在那开辟的?<br><br>procedure CombineBuffer(const Source1; Size1: Integer;<br> &nbsp;const Source2; Size2: Integer; var Dest: PChar);<br>var<br> &nbsp;p: PChar;<br>begin<br> &nbsp;GetMem(Dest, Size1 + Size2);<br> &nbsp;try<br> &nbsp; &nbsp;p := Dest;<br> &nbsp; &nbsp;Move(Source1, p^, Size1);<br> &nbsp; &nbsp;Inc(p, Size1);<br> &nbsp; &nbsp;Move(Source2, p^, Size2);<br> &nbsp;except<br> &nbsp; &nbsp;FreeMem(Dest);<br> &nbsp;end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;p: PChar;<br>begin<br> &nbsp;CombineBuffer('asd', 3, 'sss', 3, p);<br> &nbsp;try<br> &nbsp; &nbsp;MessageBox(0, p, '', 0);<br> &nbsp;finally<br> &nbsp; &nbsp;FreeMem(p);<br> &nbsp;end;<br>end;
 
接受答案了.
 

Similar threads

后退
顶部