Difference between revisions of "RPC HELP TRPCBroker OnRPCBFailure Example"

From VistApedia
Jump to: navigation, search
(Created page with "<h2>OnRPCBFailure Example</h2> For example, an application could define: Procedure HandleBrokerError(Sender: TObject); and then set: OnRPCBFailure := HandleBroker...")
(No difference)

Revision as of 17:42, 4 July 2015

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;