Difference between revisions of "RPC HELP Tutorial Step 10"

From VistApedia
Jump to: navigation, search
(Created page with "<h2>Tutorial: Step 10 -- Call Zxxx RETRIEVE RPC</h2> When a user selects a terminal type entry in the list box, the OnClick event is triggered. The new ZxxxTT RETRIEVE [[RPC_H...")
(No difference)

Revision as of 20:20, 5 July 2015

Tutorial: Step 10 -- Call Zxxx RETRIEVE RPC

When a user selects a terminal type entry in the list box, the OnClick event is triggered. The new ZxxxTT RETRIEVE RPC can be called from that OnClick event, as a replacement for the code there that simply displays the IEN of any selected record.

To use the ZxxxTT RETRIEVE RPC to display fields from a selected terminal type:

1. Create labels and edit boxes for each of the fields the RPC returns from the Terminal type file:

Terminal Type Field Add a TEdit component named Add a Label with the Caption:
.01 Name Name
1 RightMargin Right Margin:
2 FormFeed Form Feed:
3 PageLength Page Length:
4 BackSpace Back Space:
6 OpenExecute Open Execute:
7 CloseExecute Close Execute:

2. Update ListBox1's OnClick event handler. Add code so that when the user clicks on an entry in the list box, your application will call the ZxxxTT RETRIEVE RPC to retrieve fields for the corresponding terminal type, and display those fields in the set of TEdit controls on your form. This code should:

  • Set RCPBroker1's RemoteProcedure property to ZxxxTT RETRIEVE.
  • Pass the IEN of the selected terminal type to the RPC, using the TRPCBroker's runtime Param property. Pass the IEN in the Value property (i.e., brkrRPCBroker1.Param[0].Value).
  • The PType for the IEN parameter should be passed in brkrRPCBroker1.Param[0].PType. Possible types are literal, reference and list. In this case, to pass in an IEN, the appropriate PType is literal.
  • Call brkrRPCBroker1's Call method (in a try...except exception handler block) to invoke the ZxxxTT RETRIEVE RPC.
  • Set the appropriate pieces from each of the three Results nodes into each of the TEdit boxes corresponding to each returned field.
  • The code for the OnClick event handler should look like the following:
   procedure TForm1.ListBox1Click(Sender: TObject);
   var
     ien: String;
   begin
     if (ListBox1.ItemIndex <> -1) then begin {displayitem begin}        
       ien:=piece(TermTypeList[ListBox1.ItemIndex],'^',1);
       brkrRPCBroker1.RemoteProcedure:='ZxxxTT RETRIEVE';
       brkrRPCBroker1.Param[0].Value := ien;
       brkrRPCBroker1.Param[0].PType := literal;
       try          
         begin  {call code begin}
           brkrRPCBroker1.Call;
           Name.Text:=piece(brkrRPCBroker1.Results[0],'^',1);
           RightMargin.Text:=piece(brkrRPCBroker1.Results[0],'^',2);
           FormFeed.Text:=piece(brkrRPCBroker1.Results[0],'^',3);
           PageLength.Text:=piece(brkrRPCBroker1.Results[0],'^',4);
           BackSpace.Text:=piece(brkrRPCBroker1.Results[0],'^',5);
           OpenExecute.Text:=brkrRPCBroker1.Results[1];
           CloseExecute.Text:=brkrRPCBroker1.Results[2];
         end;  {call code end}
       except
         On EBrokerError do
           ShowMessage('A problem was encountered communicating with the server.');        
       end;  {try end}
     end; {displayitem end}
   end;

3. Compile and run your application. When you click on an entry in the list box now, the corresponding fields should be retrieved and displayed in the set of edit boxes on your form.

PREV: Step 9: RPC To Retrieve Terminal Types

NEXT: Step 11: Register RPCs