Buscar

Calculo de cpf

Código

Implementation

{$R *.dfm}

procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', #13, #8])then
    Key:= #13;
    if (Length(Edit1.Text) = 3)then
      Edit1.Text:= Edit1.Text+'.';

end;

procedure TForm2.MaskEdit1Exit(Sender: TObject);
var
  i: integer;
  num: string;
begin
    for i := 1 to Length(MaskEdit1.Text) do
    begin
      if MaskEdit1.Text[i] in ['0'..'9'] then
        num:= num+MaskEdit1.Text[i];
    end;
     validaCPF(num);
end;

procedure TForm2.validaCPF(num_string: string);
var
  I, J, L, somadv1, somadv2, dv1, dv2, aux: integer;
begin

  somadv1:=0;
  somadv2:=0;

  for I :=1 to 9 do
  begin
    somadv1:= somadv1 + StrToInt(num_string[I])*I;
  end;
    dv1:= somadv1 mod 11;
   L:= 0;
   for J := 1 to 9 do
     begin
      if (L <> 9)then
         begin
           somadv2:= somadv2 + StrToInt(num_string[J])*L;
           inc(L);
         end;
     end;
         aux:= somadv2 + dv1*9;
         dv2:= aux mod 11;


  Edit2.Text:= IntToStr(dv1) +','+ IntToStr(dv2);

end;

procedure TForm2.MaskEdit1KeyPress(Sender: TObject; var Key: Char);
begin
 if (Length(MaskEdit1.Text) = 9) then
    MaskEdit1Exit(Self);
end;

end.

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Arquivos
Adicionada dia: 18/08/08
Por: Anderson
Visualizada: 4320 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009