
| | | | :: :: :: :: :: :: :: :: ::
|
|
|
| |
| O CNPJ pode ser verificado através de um cálculo do dígito verificador. Isso é interessante para suas aplicações pois impede que sejam informados CNPJ inválidos. |
|
1º Coloque o código abaixo, acima do procedimento que irá fazer a chamada da verificação.
function Cnpj(xCNPJ: 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( xCNPJ )-2 do begin if Pos( Copy( xCNPJ, nCount, 1 ), '/-.' ) = 0 then begin if xx < 5 then begin fator := 6 - xx; end else begin fator := 14 - xx; end; d1 := d1 + StrToInt( Copy( xCNPJ, nCount, 1 ) ) * fator; if xx < 6 then begin fator := 7 - xx; end else begin fator := 15 - xx; end; d4 := d4 + StrToInt( Copy( xCNPJ, nCount, 1 ) ) * fator; xx := xx+1; end; end; resto := (d1 mod 11); if resto < 2 then begin digito1 := 0; end else begin digito1 := 11 - resto; end; d4 := d4 + 2 * digito1; resto := (d4 mod 11); if resto < 2 then begin digito2 := 0; end else begin digito2 := 11 - resto; end; Check := IntToStr(Digito1) + IntToStr(Digito2); if Check <> copy(xCNPJ,succ(length(xCNPJ)-2),2) then begin Result := False; end else begin Result := True; end; end;
2º No evento OnExit do campo onde será digitado o CPF coloque o código abaixo: If NOMECAMPO.Text<>'' Then If Cnpj(NOMECAMPO.Text)=False Then Begin MessageDlg('CNPJ informado é incorreto!',mtError, [mbOk],0); NOMECAMPO.SetFocus; End;
| | 
| | | |
|
Para você que quer aprender SQL, abaixo tem o link para um Objeto de Aprendizagem (OA) sobre o assunto.
Aprendendo SQL | |
|
|
| | | | "O segredo do êxito na vida de um homem está em preparar-se para aproveitar a ocasião, quando ela se apresenta." Disraelli |
|
|
| | | | :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
|
|
|
|