可能是如下的代码:procedure TFrmMain.ApplicationEvents1Exception(Sender: TObject; E: Exception);var F : TextFile ; ErrStr, ActiveForm, ErrorComponent : String ; i, j : integer ;begin if E.Message = 'There is no default printer currently selected' then begin MsgBox('没有检测到默认的打印机!') ; Exit ; end ; sbrMain.Panels[7].Text := '系统运行时发生错误,部分功能可能会受到影响!' ; try AssignFile(F,ExtractFilePath(Application.ExeName) + '/Error.log') ; if JugeErrorLog then ReWrite(F) else Append(F) ; ErrStr := FormatDateTime('YYYY-MM-DD hh:nn:ss',Now) ; WriteLn(F,ErrStr) ; ErrStr := '******发生以下错误******' ; WriteLn(F,ErrStr) ; for i := 0 to Application.ComponentCount - 1 do begin if Application.Components is TForm then begin ActiveForm := Application.Components.Name ; for j := 0 to Application.Components.ComponentCount - 1 do begin if Application.Components.Components[j] = Sender then begin ErrorComponent := Application.Components.Components[j].Name ; Break ; end ; Break ; end ; Break ; end ; end ; ErrStr := 'When ' + ActiveForm + ' is acting' ; if ErrorComponent <> '' then ErrStr := ErrStr + ' and Some object in the ' + ErrorComponent + '. Information:' ; WriteLn(F,ErrStr) ; ErrStr := E.Message ; WriteLn(F,ErrStr) ; ErrStr := ' ' ; WriteLn(F,ErrStr) ; CloseFile(F) ; except ; end ;end;