Código
If condicao then
faz a parte do then
else faz a parte do else;
eu utilizo assim:
If condicao
then faz a parte do then
else faz a parte do else;
pode parecer bobo, mas se adotarmos essa forma de identar o codigo o nosso trabalho fica bem mais claro, pra exemplificar vou colocar um pedaco de um codigo com uma identacao normalmente adotada.
{Copie essa função da dica de Roberto Claudio}
function TestaCgc(xCGC: String):Boolean;
{Testa se o CGC é válido ou não}
Var
d1,d4,xx,nCount,fator,resto,digito1,digito2 : Integer;
Check : String;
begin
xcgc := sonumeros(xcgc);
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
begin
fator := 6 - xx;
end
else
begin
fator := 14 - xx;
end;
d1 := d1 + StrToInt( Copy( xCGC, nCount, 1 ) ) * fator;
if xx < 6 then
begin
fator := 7 - xx;
end
else
begin
fator := 15 - xx;
end;
d4 := d4 + StrToInt( Copy( xCGC, 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(xCGC,succ(length(xCGC)-2),2) then
begin
Result := False;
end
else
begin
Result := True;
end;
end;
nao hora de fazer manutenção no codigo fica muito dificil saber onde esta o bloco q vc esta procurando, entao, adotando a minha tecnica ficaria assim:
function TestaCgc(xCGC: String):Boolean;
{Testa se o CGC é válido ou não}
Var d1,d4,xx,nCount,
fator,resto,digito1,digito2 : Integer;
Check : String;
begin
xcgc := sonumeros(xcgc);
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 begin
fator := 6 - xx;
end
else begin
fator := 14 - xx;
end;
d1 := d1 + StrToInt( Copy( xCGC, ,Count, 1 ) ) * fator;
if xx < 6
then begin
fator := 7 - xx;
end
else begin
fator := 15 - xx;
end;
d4 := d4 + StrToInt( Copy( xCGC, 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(xCGC,succ(length(xCGC)-2),2)
Then begin
Result := False;
end
else begin
Result := True;
end;
end;
Agora pra localiza um bloco basta achar onde o begin comeca, o primeiro end que vc achar na mesma posicao do begin é o end que fecha esse begin. Espero ter ajudado
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009