procedure TForm1.yanzhengmima;
var
ole:Olevariant;
k,h:integer;
byte1:byte;
s1:string;
begin
// 验证密码
s100 := ComboBox7.Text;
checkdata(s100);
if length(s100)<>12 then
begin
showmessage('输入错误,输入的字符长度和要求不符,请仔细检查。');
exit;
end;
initcomm;
comm.RThreshold:=0;
if comm.PortOpen=false then
comm.PortOpen:=true;
comm.DTREnable:=true;
comm.RTSEnable:=true;
ole:=VarArrayCreate([0 ,15],varByte);
ole[0]:= $4D;
ole[1]:= $4D;
for k:=1 to 12 do
begin
ole[k+1]:= ord(s100[k]);
end;
ole[14]:= $0D;
for h:= 1 to 14 do
begin
byte1:= byte1 + ole[h];
end;
s1 := inttohex(byte1 mod 256,2) ;
ole[15]:= strtoint('$'+s1);
comm.Output := ole;
sleep(50);
ole:=Comm.Input;
if ole[0] = $DD then
begin
show.Lines.Add('操作成功');
success:= true;
end
else if ole[0] = $AA then
show.Lines.Add('操作失败')
else
exit;
end;
第一次点击这个按钮就没问题,要是连续第二次点击就出现variant array index of bounds的错误。
var
ole:Olevariant;
k,h:integer;
byte1:byte;
s1:string;
begin
// 验证密码
s100 := ComboBox7.Text;
checkdata(s100);
if length(s100)<>12 then
begin
showmessage('输入错误,输入的字符长度和要求不符,请仔细检查。');
exit;
end;
initcomm;
comm.RThreshold:=0;
if comm.PortOpen=false then
comm.PortOpen:=true;
comm.DTREnable:=true;
comm.RTSEnable:=true;
ole:=VarArrayCreate([0 ,15],varByte);
ole[0]:= $4D;
ole[1]:= $4D;
for k:=1 to 12 do
begin
ole[k+1]:= ord(s100[k]);
end;
ole[14]:= $0D;
for h:= 1 to 14 do
begin
byte1:= byte1 + ole[h];
end;
s1 := inttohex(byte1 mod 256,2) ;
ole[15]:= strtoint('$'+s1);
comm.Output := ole;
sleep(50);
ole:=Comm.Input;
if ole[0] = $DD then
begin
show.Lines.Add('操作成功');
success:= true;
end
else if ole[0] = $AA then
show.Lines.Add('操作失败')
else
exit;
end;
第一次点击这个按钮就没问题,要是连续第二次点击就出现variant array index of bounds的错误。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货