Difference between revisions of "RPC HELP Tutorial Step 2"

From VistApedia
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
 
 
 
To retrieve the end-user workstation's designated server and port:
 
To retrieve the end-user workstation's designated server and port:
#  Include the RPCConf1 unit in your Pascal file's uses clause. This is the unit that [[RPC_HELP_GetServerInfo|GetServerInfo]] is a part of.
+
#  Include the RPCConf1 unit in your Pascal file's uses clause. This is the unit that [[RPC_HELP_GetServerInfo|GetServerInfo]] is a part of.  '''EDITOR'S NOTE''': this file is in the BDK folder, in the Source subfolder.
 
# Double-click on a blank region of the form. This creates an event handler procedure, TForm1.FormCreate, in your Pascal source code.
 
# Double-click on a blank region of the form. This creates an event handler procedure, TForm1.FormCreate, in your Pascal source code.
# Add code to the FormCreate event handler that retrieves the correct server and port to connect to, using the [[RPC_HELP_GetServerInfo|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.
+
# Add code to the FormCreate event handler that retrieves the correct server and port to connect to, using the [[RPC_HELP_GetServerInfo|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.  '''EDITOR'S NOTE''': At our site, and I believe many other sites, we no longer use the Windows system registry to hold the server and port values.  Instead we place them, for example with CPRS, as a command-line parameter.  For the purpose of this tutorial, I recommend hard coding in the address and port directly into the brkrRPCBroker1, and then skipping the call to [[RPC_HELP_GetServerInfo|GetServerInfo]].
  
 
The code should look like the following:
 
The code should look like the following:

Latest revision as of 14:59, 17 July 2015

RPC Broker Help Home

Tutorial Home

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. EDITOR'S NOTE: this file is in the BDK folder, in the Source subfolder.
  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. EDITOR'S NOTE: At our site, and I believe many other sites, we no longer use the Windows system registry to hold the server and port values. Instead we place them, for example with CPRS, as a command-line parameter. For the purpose of this tutorial, I recommend hard coding in the address and port directly into the brkrRPCBroker1, and then skipping the call to GetServerInfo.

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