delphi程式报错:Access violation at address 请高手帮忙!小弟感激不尽……
HDGUY 2010-04-29 11:09:03 procedure TForm_SETUP.btn_SENDTARGClick(Sender: TObject);
var
da:array[1..300] of Byte;
inbuff: array [1..32] of Byte;
str:AnsiString;
i,j,sum,port,send_len:Integer;
cs:PComStat;
nBytesRead, dwEvent, dwError:DWORD;
device_t:string;
id:Integer;
begin
port:=cbb1_port.ItemIndex+1;
InitComport(port);
id:=se_device.value;
fill_head(da, id, 'Y',0);
da[12]:=Byte(1);
da[13]:=$00;
IF rb_LEFT.Checked then
da[13]:=$01;
str:=Trim(edt_TARGET.Text);
for i:=0 to Length(str) do
begin
da[i+14]:=Byte(str[i+1]);
end;
da[Length(str)+14]:=$0;
da[10]:=1+2+Length(str)+1;
send_len:=get_sum(da,da[10]);
if (id=GB_ID) then
begin
i := MessageBox(0, 'OK!','WARING,MB_OKCANCEL);
IF (I=2) then
CloseHandle(hcomm);
end;
SendData(da,send_len);
Sleep(1);
if (id=GB_ID) then
BEGIN
CloseHandle(hComm);
ShowMessage('COMPLET!');
end;
Sleep(200);
ClearCommError(hComm,dwError,cs);
if (cs.cbInQue>SizeOf(inbuff)) then
PurgeComm(hComm, PURGE_RXCLEAR);
ReadFile(hComm, inbuff,cs.cbInQue,nBytesRead,nil);
CloseHandle(hComm);
if chk_result.Checked then//将此行拿掉时程式就能运行正常
//加上后就报:Access violation at //address 0295DB54 in module //'TEST.EXE'. Read of address 00000004
show_result(inbuff, id, 'Y');
end;