流
流浪星
Unregistered / Unconfirmed
GUEST, unregistred user!
我的一个程序中,用了comport控件,根据它的例子,编了如下代码,可无法激活事件,
请各位大虾指教。源码如下:
function card_oper(comport:tcomport;s_data:tsend_data):trec_data;
var
r_data:trec_data;
rdata:array [0..1023] of byte;
start_pos,r_count,i:integer;
myevents:tcomevents;
event:tevent;
begin
result.buff_len :=0;
event:=tevent.Create(nil,true,false,'');
start_pos:=0;
with comport do
begin
clearbuffer(true,true);
Write(s_data.send_buff,s_data.buff_len);
repeat
myevents:=[evrxchar];
waitforevent(myevents,event.handle,MAX_DELAY_RESPOND);
if evrxchar in myevents then //此时myevents为[],故下面语句未执行。But why?
begin
r_count:=read(rdata,buffer.InputSize);
for i:=0 to r_count-1 do
r_data.rec_buff[start_pos+i]:=rdata;
inc(start_pos);
end;
until myevents=[];
r_data.buff_len:=start_pos;
end;
result:=r_data;
end;
请各位大虾指教。源码如下:
function card_oper(comport:tcomport;s_data:tsend_data):trec_data;
var
r_data:trec_data;
rdata:array [0..1023] of byte;
start_pos,r_count,i:integer;
myevents:tcomevents;
event:tevent;
begin
result.buff_len :=0;
event:=tevent.Create(nil,true,false,'');
start_pos:=0;
with comport do
begin
clearbuffer(true,true);
Write(s_data.send_buff,s_data.buff_len);
repeat
myevents:=[evrxchar];
waitforevent(myevents,event.handle,MAX_DELAY_RESPOND);
if evrxchar in myevents then //此时myevents为[],故下面语句未执行。But why?
begin
r_count:=read(rdata,buffer.InputSize);
for i:=0 to r_count-1 do
r_data.rec_buff[start_pos+i]:=rdata;
inc(start_pos);
end;
until myevents=[];
r_data.buff_len:=start_pos;
end;
result:=r_data;
end;