RPC HELP TRPCBroker Connected

From VistApedia
Jump to: navigation, search

Connected Property


Applies to

   TRPCBroker component


   property Connected: Boolean;


The Connected design-time property connects your application to the VistA M Server:

  • Setting this property to True connects the application to the server.
  • Setting it to False disconnects the application from the server.

It is not necessary for your application to manually establish a connection to the VistA M Server. This version of the Broker automatically connects and disconnects from the server. When you invoke an RPC, if a connection has not already been established, one will be established for you. However, a user will not be able to run your RPC unless a context has been created with the CreateContext method.

There are other advantages to establishing a connection manually. You can check if a connection is established, and branch accordingly depending on whether a connection was established or not. One good place to do this is in your application form's OnCreate event. For that event, you could include code like the following:

     brkrRPCBroker1.Connected:= True;
     on EBrokerError do begin
       ShowMessage('Connection to server could not be established!');

This code sets the TRPCBroker component's Connected property to True to establish a connection. If a Broker exception (i.e., EBrokerError) was raised (in which case the connection wasn't established), it provides a message to the user and calls the Terminate method to exit.

To verify that your application is connected to the VistA M Server, check the value of the Connected property.

If a connected TRPCBroker component is destroyed (when the application is closed, for example), that component will first disconnect from the VistA M Server. However, for programming clarity, it is advisable to disconnect your application from the server manually by setting the Connected property to False.

If your application uses more than one Broker component, you should be aware of the component's connect and disconnect behavior.