RPC HELP TRPCBroker OnRPCBFailure Example

From VistApedia
Jump to: navigation, search

OnRPCBFailure Example

For example, an application could define:

   Procedure HandleBrokerError(Sender: TObject);

and then set:

   OnRPCBFailure := HandleBrokerError;

NOTE: The initialization of the OnRPCBFailure property should be before the first call to the TRPCBroker component.

The following instance of an error handler will take the Message property of the exception and store it with a time date stamp into a file named Error.Log in the same directory with the application exe:

   procedure TForm1.HandleBrokerError(Sender: TObject);
   var
     ErrorText: String;
     Path: String;
     StrLoc: TStringList;
     NowVal: TDateTime;
   begin
     NowVal := Now;
     ErrorText := TRPCBroker(Sender).RPCBError;
     StrLoc := TStringList.Create;
   try
     Path := ExtractFilePath(Application.ExeName);
     Path := Path + 'Error.Log';
     if FileExists(Path) then
       StrLoc.LoadFromFile(Path);
     StrLoc.Add(FormatDateTime('mm/dd/yyyy hh:mm:ss ',NowVal) + ErrorText);
     StrLoc.SaveToFile(Path);
   finally
       StrLoc.Free;
     end;
   end;