H
hansland
Unregistered / Unconfirmed
GUEST, unregistred user!
我的系统用IDUDPSERVER接收UDP数据包,并把接收到的包保存在一个数组中,然后用一个线程去显示数据,但是程序的界面就象死掉一样。怎么解决这个问题请大侠帮助解决,非常感谢。
代码如下
接收代码:
//global variant
pudparray:array[0..20000] of array[0..2047] of char;
//global variant
uid:integer=1;
//global variant
ucount:integer:=1;
procedure IDUDPSERVERread();
var ms:tmemorystream;
size:integer;
begin
zeromemory(@pudparray[ucount],2048);
size:=Adata.size;
ms:=tmemorystream.create;
Adata.seek(0,sofrombegin
ning);
ms.copyfrom(Adata,size);
ms.seek(0,sofrombegin
ning);
ms.readbuffer(pudparray[ucount],size);
ucount:=ucount:=1;
if ucount>=20000 then
ucount:=1;
end;
另起一个读pudparray[]数组的线程
constructor showdatathread.create;
....
....
showdatathread.doshowdata;
var i:integer;
begin
i:=0;
while not terminateddo
begin
if i>ucount then
sleep(3)
else
with listview.items.adddo
begin
caption:=intostr(i+1);
subitems.add(pudparray);
.....
end;
inc(i);
end;
end;
程序启动时创建showdatathread.create线程。
begin
application.processmessages;
showdatathread.create;
end;
代码如下
接收代码:
//global variant
pudparray:array[0..20000] of array[0..2047] of char;
//global variant
uid:integer=1;
//global variant
ucount:integer:=1;
procedure IDUDPSERVERread();
var ms:tmemorystream;
size:integer;
begin
zeromemory(@pudparray[ucount],2048);
size:=Adata.size;
ms:=tmemorystream.create;
Adata.seek(0,sofrombegin
ning);
ms.copyfrom(Adata,size);
ms.seek(0,sofrombegin
ning);
ms.readbuffer(pudparray[ucount],size);
ucount:=ucount:=1;
if ucount>=20000 then
ucount:=1;
end;
另起一个读pudparray[]数组的线程
constructor showdatathread.create;
....
....
showdatathread.doshowdata;
var i:integer;
begin
i:=0;
while not terminateddo
begin
if i>ucount then
sleep(3)
else
with listview.items.adddo
begin
caption:=intostr(i+1);
subitems.add(pudparray);
.....
end;
inc(i);
end;
end;
程序启动时创建showdatathread.create线程。
begin
application.processmessages;
showdatathread.create;
end;