Calculos - cgc cpf |
Top Previous Next |
|
function Cgc( xCGC:String ):Boolean; Var d1,d4,xx,nCount,fator,resto,digito1,digito2 : Integer; Check : String; begin d1 := 0; d4 := 0; xx := 1; for nCount := 1 to Length( xCGC )-2 do begin if Pos( Copy( xCGC, nCount, 1 ), '/-.' ) = 0 then begin if xx < 5 then fator := 6 - xx else fator := 14 - xx; d1 := d1 + StrToInt( Copy( xCGC, nCount, 1 ) ) * fator; if xx < 6 then fator := 7 - xx else fator := 15 - xx; d4 := d4 + StrToInt( Copy( xCGC, nCount, 1 ) ) * fator; xx := xx+1; end; end; resto := (d1 mod 11); if resto < 2 then digito1 := 0 else digito1 := 11 - resto; d4 := d4 + 2 * digito1; resto := (d4 mod 11); if resto < 2 then digito2 := 0 else digito2 := 11 - resto; Check := IntToStr(Digito1) + IntToStr(Digito2); if Check <> Right( xCGC, 2 ) then Result := False else Result := True; end;
function Cpf( xCPF:String ):Boolean; Var d1,d4,xx,nCount,resto,digito1,digito2 : Integer; Check : String; begin d1 := 0; d4 := 0; xx := 1; for nCount := 1 to Length( xCPF )-2 do begin if Pos( Copy( xCPF, nCount, 1 ), '/-.' ) = 0 then begin d1 := d1 + ( 11 - xx ) * StrToInt( Copy( xCPF, nCount, 1 ) ); d4 := d4 + ( 12 - xx ) * StrToInt( Copy( xCPF, nCount, 1 ) ); xx := xx+1; end; end; resto := (d1 mod 11); if resto < 2 then digito1 := 0 else digito1 := 11 - resto; d4 := d4 + 2 * digito1; resto := (d4 mod 11); if resto < 2 then digito2 := 0 else digito2 := 11 - resto; Check := IntToStr(Digito1) + IntToStr(Digito2); if Check <> Right( xCPF, 2 ) then Result := False else Result := True; end;
|