Rotina para pegar erros no Delphi
31/03/2003
0
olá, gostaria de saber como faço para pegar todo o error do delphi e jogar para um arq. texto.
Edgriffo
Curtir tópico
+ 0
Responder
Posts
31/03/2003
Nildo
Segue aqui a unit completa...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure capturaErros(Sender: TObject; e: Exception);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.capturaErros(Sender: TObject; e: Exception);
var
arq: TStringList;
begin
arq := TStringList.create;
if fileExists(extractFilePath(paramStr(0)) + ´erros.txt´) then
arq.loadFromFile(extractFilePath(paramStr(0)) + ´erros.txt´);
arq.add (dateToStr(date) + ´ - ´ + (Sender as TComponent).name + ´ causou o seguinte erro: ´ + e.Message);
arq.saveToFile(extractFilePath(paramStr(0)) + ´erros.txt´);
arq.free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
application.onException := CapturaErros;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure capturaErros(Sender: TObject; e: Exception);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.capturaErros(Sender: TObject; e: Exception);
var
arq: TStringList;
begin
arq := TStringList.create;
if fileExists(extractFilePath(paramStr(0)) + ´erros.txt´) then
arq.loadFromFile(extractFilePath(paramStr(0)) + ´erros.txt´);
arq.add (dateToStr(date) + ´ - ´ + (Sender as TComponent).name + ´ causou o seguinte erro: ´ + e.Message);
arq.saveToFile(extractFilePath(paramStr(0)) + ´erros.txt´);
arq.free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
application.onException := CapturaErros;
end;
end.
Responder
Clique aqui para fazer login e interagir na Comunidade :)