listview,如何把收到的报保存到listview的中,并提取出来?

如何把收到的报保存到listview的中,并提取出来? - 故障解答 - 电脑教程网

如何把收到的报保存到listview的中,并提取出来?

日期:2006-08-18   荐:
如何把收到的报保存到listview的中,并提取出来?我通过dll调用接收到udp报ServRecBuff,数据结构为ServRecBuff= record optiontype : byte raceType : byte msgcontent array[0..299] of charend;其中,msgcontent 对应数据结构struct1,struct1=record name: array[0..3]of char url:array[0..200]of charend;我想把接受到的报ServRecBuff1保存到listview中,然后再通过双击把数据取出来,如果不保存数据直接读,显示结果是正确的,保存以后再读便出错,奇怪!请大侠帮忙!代码如下:procedure TForm1.IdUdpServerRead(Sender:TObject;Adata:TStream:ABinding:TIdSocketHandle);var ServRecBuff1:ServRecBuff; ms:TMemoryStream; size,ret,i:integer;begin size:=Adata.size; ZeroMemory(@ServRecvBuff1,sizeof(ServRecvBuff1)); ms:=TMemoryStream.Create; AData.Seek(0,soFromBeginning); ms.Seek(0,soFromBeginning); ms.ReadBuffer(ServRecvBuff1,size); with listview1.items.add do begin caption:='note'; for i:=0 to 299 do ServRecBuff1.msgcontent[i]:=ServRecBuff1.msgcontent[i 1]; ret:=decodeall_req_rep(ServRecBuff1.msgcontent,struct1);//dll调用 //subitems.add(ServRecBuff1.msgcontent); //在listview1中不保存ServRecBuff1.msgcontent,直接显示则取出的数据是正确的end;上面代码为在listview1中不保存ServRecBuff1.msgcontent,直接调用dll,显示结果发现,取出的数据是正确的。奇怪的是先把ServRecBuff1.msgcontent保存到listview1中,然后再调用dll显示结果,取出的数据不正确,或者部分正确。代码如下,请大虾帮助解决,多谢!procedure TForm1.IdUdpServerRead(Sender:TObject;Adata:TStream:ABinding:TIdSocketHandle);var ServRecBuff1:ServRecBuff; ms:TMemoryStream; size,ret,i:integer;begin size:=Adata.size; ZeroMemory(@ServRecvBuff1,sizeof(ServRecvBuff1)); ms:=TMemoryStream.Create; AData.Seek(0,soFromBeginning); ms.Seek(0,soFromBeginning); ms.ReadBuffer(ServRecvBuff1,size); with listview1.items.add do begin caption:='note'; for i:=0 to 299 do ServRecBuff1.msgcontent[i]:=ServRecBuff1.msgcontent[i 1]; //ret:=decodeall_req_rep(ServRecBuff1.msgcontent,struct1);//dll调用 subitems.add(ServRecBuff1.msgcontent);end;procedure TForm1.listview1Dbclick(Sender:TObject);var selitem:tlistitem; i,ret:integer; msgcontent:array[0..299]of char;begin listview1.viewstyle:=vsReport; if listview1.selected<>nil then begin i:=listview1.selected.index; strPcoy(msgcontent,listview1.items[i].subitem[0]); ret:=decodeall_req_rep(msgcontent,struct1);//dll调用 end; ......... end; end;是不是保存之后,dll调用返回就出问题了........仔细检查一下嘛.....看看返回数据顶一下!是保存以后dll调用返回出现问题,不知如何解决。为何别的保存不出问题?
标签: