March 2000
Intermediate to advanced
576 pages
18h 13m
English
ExceptProc Variable
var ExceptProc: Pointer; procedureMyProc(ExceptObject: TObject; ExceptAddr: Pointer); begin ... end; ... ExceptProc := @MyProc;
If an exception is not handled in a try-except
block and ExceptProc is not
nil, Delphi calls the procedure that
ExceptProc points to, passing as arguments a
reference to the exception object and the address where the exception
originated. If ExceptProc is
nil, Delphi raises runtime error
217.
// Log exceptions in an application event log (in Windows NT).
procedure LogException(ExceptObject: TObject; ExceptAddr: Pointer);
var
ApplicationName: string;
Handle: THandle;
Msg: string;
Strings: array[0..0] of PChar;
begin
ApplicationName := ChangeFileExt(ExtractFileName(ParamStr(0)), '');
// Change the application path to its base name, e.g., 'App'.
// The application must have created the appropriate register key.
Handle := RegisterEventSource(nil, PChar(ApplicationName));
// Get the exception message.
if ExceptObject is Exception then
Msg := Exception(ExceptObject).Message
else
Msg := ExceptObject.ClassName;
Strings[0] := PChar(Msg);
// Define the Category and Exception_ID elsewhere.
ReportEvent(Handle, EventLog_Error_Type, Category, Exception_ID,
nil, 0, 1, @Strings, nil);
DeregisterEventSource(Handle);
end;
...
ExceptProc := @LogException;| ErrorProc Variable, Raise Keyword |
Read now
Unlock full access