我要较验一组数据
function IsArrayValid(BA:string):Boolean;
var
      i,mint:integer;
      mbyte:byte;
      marray:array of integer;
      mstr:string;begin          mbyte:=$d2;
      for i:=1 to 29 do
      begin
           setlength(marray,29);        
           marray[i-1]:=strtoint(ba[i]);
           mbyte:=mbyte xor marray[i-1];
      end;
      mint:=strtoint(ba[30]);
      if mbyte<>mint then
           result :=false
      else
           result :=true;      
end;function IsValid(BA:string):Boolean;
var
      i,mhigh,mint:integer;
      mbyte:byte;
      marray:array of integer;
      mx:string;begin
     
      mbyte:=$d2;
      for i:=7 to mhigh-2 do
      begin
           setlength(marray,mhigh-8);
           mx:=ba[i];
           mint := strtoint(mx);
           marray[i-7]:=mint;
           mbyte:=mbyte xor marray[i-7];
      end;
      mint:=strtoint(ba[mhigh-1]);
      if mbyte<>mint then
           result :=false
      else
           result :=true;      
end;

解决方案 »

  1.   

    function IsArrayValid(BA:string):Boolean;
    var
          i,mint:integer;
          mbyte:byte;
          marray:array of integer;
          mstr:string;begin          mbyte:=$d2;
          for i:=1 to 29 do
          begin
               setlength(marray,29);          //设定数组长度
               marray[i-1]:=strtoint(ba[i]);  //把字符串转化为整形数组
               mbyte:=mbyte xor marray[i-1];  //异或
          end;
          mint:=strtoint(ba[30]);             //校验位
          if mbyte<>mint then
               result :=false
          else
               result :=true;      
    end;