Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture and report error

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have the following piece of code that was written by a former co-worker:

Code:
Except
  Pnl_Msg.Visible:= False;
  Beep;
  Form_Dialog.Caption:= ' Warning';
  Form_Dialog.Lbl_Msg1.Caption:=
    'System can''t accept check-in at this time';
  Form_Dialog.Lbl_Msg2.Caption:= 'Please check-in with Courtroom Clerk';
  Form_Dialog.Btn_Yes.Visible:= False;
  Form_Dialog.Btn_No.Visible:= False;
  Form_Dialog.Btn_Ok.Visible:= True;
  Form_Dialog.ShowModal;
  Btn_CheckIn.Enabled:= True;
  FormActivate(Self);
  Exit;
End;

It has now become necessary to actually trap and report the error that is thrown when the user gets the 'System can't accept check in at this time'. So I decided I would use another piece of code from another project, that actually reports the error:
Code:
except
  on e:Exception do
  begin
    ShowMessage('Error Connecting to Database-' + e.Message);
  end;
end;

But when I put it all together, I get an error:
This form of method call only allowed for class methods
Here's what I have:
Code:
Except
  on e:Exception do
  begin
    TDMod.LogError(Now(), e.Message); //write time & error to log
    Pnl_Msg.Visible:= False;
    Beep;
    Form_Dialog.Caption:= ' Warning';
    Form_Dialog.Lbl_Msg1.Caption:=
      'System can''t accept check-in at this time';
    Form_Dialog.Lbl_Msg2.Caption:= 'Please check-in with Courtroom Clerk';
    Form_Dialog.Btn_Yes.Visible:= False;
    Form_Dialog.Btn_No.Visible:= False;
    Form_Dialog.Btn_Ok.Visible:= True;
    Form_Dialog.ShowModal;
    Btn_CheckIn.Enabled:= True;
    FormActivate(Self);
    Exit;
  end;
End;

I guess I need to create an instance of the Exception class? How would I do that?

Thanks!

leslie
 
Ok, I found a way around this problem by putting all the code from the LogError procedure directly in the EXCEPT, but I'd still like to know how to do this the way I originally wanted.

Thanks!
leslie
 
is TDMod a variable or class type? If it's a class type, then you may need to Create an instance of TDMod first.

 
It's the DataModule and it's already been created at this point in the code.
 
Is the data module defined as:

var
DMod: TDMod;

or as:

var
TDMod: TTDMod;

???

If the 1st one, then change "TDMod" to "DMod"

Roo
Delphi Rules!
 
it's like the first one:
Code:
unit CheckInDB;

interface

uses
  SysUtils, Classes, Scdconn, Scdcall, DB, DBTables, Forms;

type
  TDMod = class(TDataModule)
    Database1: TDatabase;
    Qry_LastCheckIn: TQuery;
    Qry_GetOffcrInfo: TQuery;
    Call_SendNotification: TCall400;
    Qry_GetExistingMsg: TQuery;
    Qry_IncTimeSort: TQuery;
    Qry_AddCheckin: TQuery;
    Qry_NewRecord: TQuery;
    Qry_GetAllTimes: TQuery;
    AS400: TAS400;
    Qry_GetMsgQueue: TQuery;
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure LogError(ErrorTime : TDateTime; ErrorMessage : string);
  end;

var
  DMod: TDMod;

const
  sAdditive: string = '1912';

implementation
 
yep, so change your reference to
Code:
DMod.LogError(Now(), e.Message); //write time & error to log

While your code can be correct in certain circumstances, you generally have to refer to the variable, not the class type.
 
Ok, I see what I did now, thanks for showing me the light!

duh!

leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top