Ir para conteúdo
Fórum Script Brasil
  • 0

Access Violation (Auto Resolvido)


pdelphi

Pergunta

A minha aplicação, tem um arquivo de configuração, para toda vez que ele for executado, ele lê essas informações e depois execute-as conforme o configurado. Em realidade, são comandos SQL, para serem executados conforme o necessitado. Acontece, que, se o arquivo sql.cfg, não estiver no diretório, ele dá um erro de ACCESS VIOLATION. Até aí norma. Eu faço uma pergunta, se o arquivo existe ou não. Caso não exista, ele deve criar antes de qualquer coisa, para depois fazer o que deve. Conclusão continua dando oerro de ACCESS VIOLATION. Veja os códigos:

Nesta procedure, apresenta o erro:

procedure TfrmConfig.gravasql;

var

txt,path1 : string;

sql1:textfile;

begin

txt := '';

    with DMARQ.qryTec do begin

      sql.clear;

      sql.Add('select posicao, naladi, descricao, ii, ipi, pis, confins, icms, um, conv, OBSEX from tec ');

      if not(cbExII.Checked) then

      txt := 'where (tipo <> 41)';

      if not(cbExIPI.Checked) then

      if txt = '' then txt := 'where (tipo <> 42)' else txt := txt +'and (tipo <> 42)';

      if not(cbNaladi.Checked) then

      if txt = '' then txt := 'where (tipo <> 50)' else txt := txt +'and (tipo <> 50)';

      if not(cbtitulo.Checked) then

      if txt = '' then txt := 'where (tipo <> 0)' else txt := txt +'and (tipo <> 0)';

      if not(cbPosicao.Checked) then

      if txt = '' then txt := 'where (tipo <> 1)' else txt := txt +'and (tipo <> 1)';

      if not(cbPosicaoCheia.Checked) then

      if txt = '' then txt := 'where (tipo <> 2)' else txt := txt +'and (tipo <> 2)';

      if not(cbSubPos.Checked) then

      if txt = '' then txt := 'where (tipo <> 3)' else txt := txt +'and (tipo <> 3)';

      if not(cbOutros.Checked) then

      if txt = '' then txt := 'where (tipo <> 40)' else txt := txt +'and (tipo <> 40)';

      if not(cbIcms.Checked) then

      if txt = '' then txt := 'where (tipo <> 1) or (tipo <> 2)' else txt := txt +'and (tipo <> 1) or (tipo <> 2)';

      if not(cbUnidade.Checked) then

      if txt = '' then txt := 'where (tipo <> 1) or (tipo <> 2) or (tipo <> 3)' else txt := txt +'and (tipo <> 1) or (tipo <> 2) or (tipo <> 3)';

      txt := txt + ' order by posicao, ant ';

      sql.Add(txt)

end;

path1:=ExtractFilePath(ParamStr(0))+'sql.cfg';

AssignFile(sql1, path1);

Rewrite(sql1);

Writeln(sql1, txt);

closefile(sql1);

//close;

end;

No botão para chamar a procedure, eu coloco também so códigos para gravar o arquivo, caso ele não exista. OBS: Já coloquei esse código, no DPR e também na procedure gravasql, e continuou a dar o mesmo erro:

procedure TfrmConfig.BitBtn1Click(Sender: TObject);

var

sql1:Textfile;

begin

if edit1.text = '' then begin

showmessage('Você deve informar o endereço de gravação!');

exit;

end;

if not fileexists(ExtractFilePath(ParamStr(0))+'sql.cfg') then begin

    AssignFile(sql1, ExtractFilePath(ParamStr(0))+'sql.cfg');

    Rewrite(sql1);

    Writeln(sql1, ' order by posicao, ant ');

    closefile(sql1);

end;

try

  frmPrincipal.Timer1.Enabled:=False;

  gravatxt;

  gravasql;

finally

  frmPrincipal.Timer1.Enabled:=True;

  close;

end;

end;

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Visitante
Este tópico está impedido de receber novos posts.


  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...