Mega Code Archive

 
Categories / Delphi / Files
 

Creating a errors log file to facility the technical support

Title: Creating a errors log file to facility the technical support. Question: How can I create a log of errors of my systems? Answer: How can I create a rotine to create a log of all erros ocurred in my system? With this code is possible creating a log file contained the Data, Time, Form and Control where the error occured and a message of error. This rotine will facilitate the work of technical support distances. To create this error log file we will use a TTable object. Firstly put one TTable in your main form and configure the properties below: DatabaseName = C:\ (local where the log file will be created ) Name = tbErrors TableName = errors.log TableType = ttAscii Now, you must declare the procedure in private section of your main form: ... private {private declarations} procedure CapErrors(Sender: TObject; E: Exception); public {public declarations} ... Put the procedure below in implemantation section of your main form: procedure TForm1.CapErrors(Sender: TObject; E: Exception); var msg: String; begin tbErrors.Open; try tbErrors.Append; tbErrors.Fieldbyname('DataHora').Value := FormatDateTime( 'dd/mm/yyyy hh:nn:ss', Now ); tbErrors.Fieldbyname('Form').AsString := Screen.ActiveForm.Name; tbErrors.Fieldbyname('Control').AsString := Screen.ActiveControl.Name; tbErrors.Fieldbyname('Menssage').AsString := E.Message; tbErrors.Post; finally tbErrors.Close; end; // Show the message to your user msg := E.Message + #10 + #10; msg := msg + 'Form: ' + Screen.ActiveForm.Name + #10; msg := msg + 'Control: ' + Screen.ActiveControl.Name; Application.MessageBox( PChar( msg ), 'Error', mb_IconError ); end; In the procedure OnFormCreate of your main form you must put the code below: procedure TForm1.FormCreate(Sender: TObject); begin ... Application.OnException := CapErrors; ... end; Ok, with this rotine the log file (errors.log) will be created in c:\ containd all erros not negotiate in your system. Fabrcio Fadel Kammer System Analyser ABCS Informtica Conchal - SP - Brazil