Difference between revisions of "RPC HELP Tutorial Step 2"

From VistApedia
Jump to: navigation, search
(Created page with "<h2>Tutorial: Step 2 -- Get Server/Port</h2> The TRPCBroker component you've added to your form is hard coded to access the Broker server and listener ...")
(No difference)

Revision as of 17:02, 5 July 2015

Tutorial: Step 2 -- Get Server/Port

The TRPCBroker component you've added to your form is hard coded to access the Broker server and listener port that it picks up from your own (developer) workstation (by default, BROKERSERVER and 9200). Naturally you don't want this to be the only server and port that your application can connect to. To retrieve the end-user workstation's designated Broker server and port to connect to, as stored in their Registry, you can use the GetServerInfo function.

To retrieve the end-user workstation's designated server and port:

  1. Include the RPCConf1 unit in your Pascal file's uses clause. This is the unit that GetServerInfo is a part of.
  2. Double-click on a blank region of the form. This creates an event handler procedure, TForm1.FormCreate, in your Pascal source code.
  3. Add code to the FormCreate event handler that retrieves the correct server and port to connect to, using the GetServerInfo function. If mrCancel is returned, your code should quit. Otherwise, your code should then set brkrRPCBroker1's Server and ListenerPort properties to the returned values.

The code should look like the following:

   procedure TForm1.FormCreate(Sender: TObject);
   var ServerStr: String;
     PortStr: String;
   begin
     // Get the correct port and server from the Registry.
     if GetServerInfo(ServerStr,PortStr)<> mrCancel then begin
       brkrRPCBroker1.Server:=ServerStr;
       brkrRPCBroker1.ListenerPort:=StrToInt(PortStr);
       {connectOK}
     end else begin
       Application.Terminate;    
     end;
   end;


Now that you have code to retrieve the appropriate RPC Broker server and listener port, in the next section of the tutorial (Step 3) your application will use the TRPCBroker component to establish a connection to the VistA M Server.

PREV: Step 1: Create Application with an RPC Broker Component

NEXT: Step 3: Establish Broker Connection