|
Como Capturar Nombre u Origen en Control de Errores
Hola a todo/as:
Tengo un código de control de errores que se asigna desde el create o activate de una forma, cuando envia la excepción la captura bien y crea un archivo Log pero no he podido capturar el nombre del componente que la genera...si me pudieran dar una mano se los agradeceria...
//** en el create...
Application.OnException:=controlErrores;
procedure TForm1.controlErrores(Sender: Tobject; E: Exception);
//** Gina Ma Silva Mejia Controla los errores no controlados de la aplicación por try o onexception
var
sMensaje,ls_cadena,path,ls_opcion,b : string;
i,j : integer;
a: ShortString;
begin
path := ExtractFilePath(ParamStr(0)); /** toma el path desde donde se ejecuta la aplicacion
if E is EDivByZero then
sMensaje := 'ERROR: División Por Cero'
else if E is ERangeError then
sMensaje := 'ERROR: Rango Erróneo'
else if E is ERangeError then
sMensaje := 'ERROR: Desbordamiento'
else if E is EConvertError then
sMensaje := 'ERROR: Número No Válido'
else if E is EIntOverflow then
sMensaje := 'ERROR: Entero Demasiado Grande'
else if E is EConvertError then
sMensaje := 'ERROR: Número No Válido'
else if E is EDBEngineError then
sMensaje := 'ERROR en la Base de Datos'
else if E is EAccessViolation then
sMensaje := 'ERROR de Memoria'
else if E is EListError then
sMensaje := 'ERROR: La lista esta Vacia'
else
sMensaje := 'ERROR: Error General';
RichEdit12.Lines.Clear;
RichEdit12.PlainText := True;
/** en esta variable b pretendo capturar el nombre del sender que genero la excepcion pero me ha tocado asi:
b:='';
if sender.ClassName = 'TTimer' then
b:= TTimer(sender).Name;
if sender.ClassName = 'TStringGrid' then
b:= TStringGrid(sender).Name;
if sender.ClassName = 'TCheckListBox' then
b:= TCheckListBox(sender).Name;
if sender.ClassName = 'TSpeedButton' then
b:= TSpeedButton(sender).Name;
ls_cadena:= formatdatetime('dd/mm/yyyy hh:mm:ss',now())+' '+b+' '+ Sender.ClassName +' '+E.ClassName +' '+E.Message;
Memo13.Lines.Add(ls_cadena);
for i := 0 to Memo13.Lines.Count - 1 do
begin
ls_cadena := Memo13.Lines.Strings[i];
RichEdit12.Lines.add(ls_cadena);
end;
RichEdit12.Lines.SaveToFile(path +'\Log.txt');
end;
with TFrmMensajes.Crear(Self, sMensaje, E) do
ShowModal;
end;
/*** tienen un form TFrmMensajes para mostrar el error...
unit UnitMensajes;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons;
type
TFrmMensajes = class(TForm)
Panel1: TPanel;
BtnDetalles: TButton;
STDetalles: TStaticText;
Panel2: TPanel;
STError: TStaticText;
BitBtn1: TBitBtn;
procedure BtnDetallesClick(Sender: TObject);
public
{ Public declarations }
constructor Crear(AOwner: TComponent; Mensaje: string; E: Exception);
end;
var
FrmMensajes: TFrmMensajes;
implementation
{$R *.DFM}
constructor TFrmMensajes.Crear(AOwner: TComponent; Mensaje: string; E: Exception);
begin
inherited Create(AOwner);
Height := 130;
//****Recibe un mensaje de error y una excepción.
STError.Caption := Mensaje;
STDetalles.Caption := E.ClassName + ': ' + E.Message;
end;
procedure TFrmMensajes.BtnDetallesClick(Sender: TObject);
begin
if BtnDetalles.Caption = '>> Detalles' then
begin
height := 230;
BtnDetalles.Caption := '<< Detalles';
end
else
begin
height := 130;
BtnDetalles.Caption := '>> Detalles';
end
end;
end.
|