我在调试delphi时出现了一个错误,调了大半天都不知道错哪,能不能帮我看下
错误:
Project project1.exe raised exception class EaccessViolation with message
‘Access violation at address 0040414EA in module’project1.exe’.Read
Of address 50472C43’.Process stopped.Use Step or Run to continre;
程序错误的位置:
procedure TForm1.BitBtn2Click(Sender: TObject);//按键2
begin
{sbuf[0] :=$53; //534156310D0A
sbuf[1] :=$41;
sbuf[2] :=$56;//帧头
sbuf[3] :=$31;//命令号
sbuf[4] :=$0D;
sbuf[5] :=$0A;senddata;//调用发送函数}
StrData:='SAV1';//错在这里
SChar_and_Send();
end; 
上面程序是我在接收PIC串口数据后,要再向PIC串口发送数据时出现的错误.
用FT232USB转串口芯片. 

解决方案 »

  1.   

    下面是代码:
    procedure SChar_and_Send();
    begin
    SetChar(StrData);
    senddata;
    end;procedure SetChar(var x:string);
    var
      i,Len:byte;
    begin
      Len:=length(x)+2;
      setlength(sbuf,Len);
      for i:=0 to len-3 do
        begin
          sbuf[i]:=ord(x[i+1]);
        end;
      sbuf[i]:=$0D;
      i:=i+1;
      sbuf[i]:=$0A;
    end;procedure senddata;
    var
    i:integer;
    commflg:boolean;
    begin
      viewstring:='';
      commflg:=true;
      for i:=0 to length(StrData)+1 do
        begin
          if not Form1.comm1.writecommdata(@sbuf[i],1) then
            begin
               commflg:=false;
               break;
            end;
          sleep(1);//发送时字节间的延时      viewstring:=viewstring+ inttohex(sbuf[i],2)+' ';    end;  viewstring:='发送'+ viewstring;  Form1.memo1.lines.add(viewstring);  Form1.memo1.lines.add('');  if not commflg then messagedlg('发送失败 !' ,mterror,[mbyes],0);
      //sleep(2000);
      //if(comrs=false)then senddata;
    end;