Fórum Convertendo dados de texto para firebird erro access violation at address #472825
13/03/2014
0
Amigos, estou com um problema que ta me tirando o sono:
Tenho uma rotina para fazer conversão de projeto. Acontece que ela da erro de access violation at address nem sempre na mesma linha e pior ainda nem sempre da o erro. O que notei é que na maioria dos arquivos TXT grandes o erro ocorre. Mas também como disse, algumas vezes não.
Segue o trecho do código. Se alguém puder me ajudar agradeço.
Tenho uma rotina para fazer conversão de projeto. Acontece que ela da erro de access violation at address nem sempre na mesma linha e pior ainda nem sempre da o erro. O que notei é que na maioria dos arquivos TXT grandes o erro ocorre. Mas também como disse, algumas vezes não.
Segue o trecho do código. Se alguém puder me ajudar agradeço.
if cbCad.Checked then begin
try
//CADASTRO (CADPRI.TXT) ====================================================
iTotLin := PegaNroLinhasTXT(edCaminho.Text + ''CADPRI.TXT'');
iLinAtu := 0;
//Abrindo o arquivo
AssignFile(sTxtF, edCaminho.Text + ''CADPRI.TXT'');
//Abre somente para leitura
Reset(sTxtF);
lbStatus.Caption := ''Importando Cadastros...'';
ProgressBar1.Max := iTotLin;
dm.tbCadGAbrir();
while not eof(sTxtF) do begin
Readln(sTxtF, sLinha);
inc(iLinAtu);
lbStatus.Caption := ''Importando Cadastros. Linha '' + inttostr(iLinAtu) + '' de '' + inttostr(iTotLin);
Application.ProcessMessages;
ProgressBar1.Position := iLinAtu;
if bCancelou then begin
Cancela;
exit;
end;
if (Length(sLinha) < 5) then //SisGer DOS, deixa um caractere especial na última linha
Continue;
//rotina especial para importação dos bancos diretamente pelo sistema ao final do cadastramento
if (Copy(sLinha, 1, 9) = ''IMPBANCOS'') then begin
bImpBancos := true;
Continue;
end;
//Nova sistematica de busca
if (rgTipoImp.itemindex = 0) then
bBusca := false
else
bBusca := dm.tbCadG.Locate(''CODIGO'', StrToIntDef(Copy(sLinha, 1, 10), 0), [loCaseInsensitive]);
if (bBusca) and (rgTipoImp.itemindex = 1) then
dm.tbCadG.Edit
else if (bBusca) and (rgTipoImp.itemindex = 2) then
continue
else
dm.tbCadG.Insert;
dm.tbCadGCODIGO.Value := StrToIntDef(Copy(sLinha, 1, 10), 0);
if cbConv.Checked then
dm.tbCadGNOME.Value := ConvDos(Trim(Copy(sLinha, 11, 60)))
else
dm.tbCadGNOME.Value := Trim(Copy(sLinha, 11, 60));
if dm.tbCadGNOME.IsNull then
dm.tbCadGNOME.Value := ''NOME NAO INFORMADO'';
if cbConv.Checked then
dm.tbCadGFANTASIA.Value := ConvDos(Trim(Copy(sLinha, 71, 60)))
else
dm.tbCadGFANTASIA.Value := Trim(Copy(sLinha, 71, 60));
dm.tbCadGPFJ.Value := Trim(Copy(sLinha, 131, 1));
dm.tbCadGCLILIBFAT.Value := Trim(Copy(sLinha, 132, 1));
dm.tbCadGLIMITECRED.Value := ViraFloat(Copy(sLinha, 133, 15), ''.'');
dm.tbCadGSITE.Value := Trim(Copy(sLinha, 148, 50));
dm.tbCadGEMAIL.Value := Trim(Copy(sLinha, 198, 50));
dm.tbCadGDTNASC.Value := Trim(Copy(sLinha, 248, 5));
dm.tbCadGCODBUSCA.Value := Trim(Copy(sLinha, 258, 15));
dm.tbCadGSITUACAO.Value := Trim(Copy(sLinha, 273, 1));
dm.tbCadGNROCOMPENS.Value := Trim(Copy(sLinha, 274, 3));
dm.tbCadGEMAILNFE.Value := Trim(Copy(sLinha, 277, 50));
Case Copy(sLinha, 327, 1)[1] of
''C'': dm.tbCadGFCLI.Value := ''S'';
''F'': dm.tbCadGFFOR.Value := ''S'';
''B'': dm.tbCadGFBAN.Value := ''S'';
''V'': dm.tbCadGFVEN.Value := ''S'';
''R'': dm.tbCadGFREP.Value := ''S'';
end;
if length(PegaSoNro(Trim(Copy(sLinha, 328, 10)))) = 8 then
dm.tbCadGDTULTATUDATA.AsString := Trim(Copy(sLinha, 328, 10))
else
dm.tbCadGDTULTATUDATA.value := now;
dm.tbCadG.Post;
if cbCommit.Checked and dm.dbt.InTransaction then
dm.dbt.CommitRetaining;
end;
//Fechar o o arquivo
CloseFile(sTxtF);
except
on E: Exception do begin
MensErro(''Linha: ''+ IntToStr(iLinAtu) +#13+ ''Erro: ''+ E.Message);
end;
end;
end;
Alexandre Faustinoni
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)