A
Andyli
Unregistered / Unconfirmed
GUEST, unregistred user!
看了很多有关ClientSocket的贴子,很大一部分在用ClientSocket控件的SendStream(myStream)后,都在后面加多了myStream.Free,但我在实际用的过程中如果加上myStream.Free一句,则程序会报错,大富翁上也有前辈提到说myStream是由ClientSocket自己管理,sendStream后就释放了,但是那么多贴子都在后面写有myStream.Free,难道说那么多人的代码都有问题??在离线包上随便找一个贴上来,大家谈谈下面代码最后是否要加上Sendstream.Free这句???procedure sendrecord;varsendem :EmpMessage;grecorcount:Byte;recordsize:integer;SendStream :tmemorystream;begin grecorcount:=3; Setlength(sendem.G_record,grecorcount); recordsize:=sizeof(EmpMessage) +grecorcount*sizeof(GoodsRec);//注意这里!! sendem.grecorcount:=grecorcount; sendem.ename:='test'; ......//填完其他的数据 sendem.G_record[0].goodsid:='aaaaaaaaaa'; sendem.G_record[0].goodsname:='bbbbbbbbb'; ...... sendem.G_record[grecorcount].goodsid:='fffffff'; sendem.G_record[grecorcount].goodsname:='zzzzzzzz'; SendStream:=Tmemorystream.create; try Sendstream.write(sendem,recordsize); Sendstream.position:=0; clientsocket.sendStream(sendstream);finally Sendstream.free;end;end;