function TForm1.convert_str(str:String):String; //计算校验位 var maxLength:integer; i:integer; num:integer; begin maxLength:= Length(str); num:= 0; for i := 1 to maxlength do begin if i mod 2 = 0 then num:= num + strtoint(copy(str,i,1))*3; if i mod 2 = 1 then num:= num + strtoint(copy(str,i,1)); end; maxLength:= Length(inttostr(num)); if copy(inttostr(num),maxLength,1) = '0' then Result:= '0' else //Result:= IntToStr(10 - StrToInt(copy(inttostr(num),maxLength,1))); result:=inttostr((10 - (num mod 10)) mod 10); end;
var maxLength:integer;
i:integer;
num:integer;
begin
maxLength:= Length(str);
num:= 0;
for i := 1 to maxlength do
begin
if i mod 2 = 0 then
num:= num + strtoint(copy(str,i,1))*3;
if i mod 2 = 1 then
num:= num + strtoint(copy(str,i,1));
end;
maxLength:= Length(inttostr(num));
if copy(inttostr(num),maxLength,1) = '0' then
Result:= '0'
else
//Result:= IntToStr(10 - StrToInt(copy(inttostr(num),maxLength,1)));
result:=inttostr((10 - (num mod 10)) mod 10);
end;