Código
var
j, Mult, Soma, Digito1, Digito2, Incr_dig2: integer;
CNH_Forn, Dig_Forn, Dig_Enc : string;
begin
Result := 'F';
if length(Trim(PVRegCnh)) < 11 then
Exit;
CNH_Forn := Copy(PVRegCnh,1,9);
Dig_Forn := Copy(PVRegCnh,10,2);
Incr_Dig2 := 0;
Soma := 0;
Mult := 9;
for j := 1 to 9 do
begin
Soma := Soma + (StrToInt(CNH_Forn[j]) * Mult);
Mult := Mult - 1;
end;
Digito1 := Soma Mod 11;
if Digito1 = 10 then
begin
Incr_Dig2 := -2;
end;
if Digito1 > 9 then
begin
Digito1 := 0;
end;
Soma := 0;
Mult := 1;
for j := 1 to 9 do
begin
Soma := Soma + (StrToInt(CNH_Forn[j]) * Mult);
Mult := Mult + 1;
end;
if (Soma Mod 11) + Incr_Dig2 < 0 then
begin
Digito2 := 11 + (Soma Mod 11) + Incr_Dig2;
end;
if (Soma Mod 11) + Incr_Dig2 >= 0 then
begin
Digito2 := (Soma Mod 11) + Incr_Dig2;
end;
if Digito2 > 9 then
begin
Digito2 := 0;
end;
Dig_Enc := IntToStr(Digito1)+IntToStr(Digito2);
if Dig_Forn = Dig_enc then
begin
Result := 'V';
end;
if Dig_Forn <> Dig_enc then
begin
Result := 'F';
end;
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009