Step 6. Call the ZxxxTT LIST RPC

Now that you have created and tested the ZxxxTT LIST RPC on the M server system, you can use your Delphi application's TRPCBroker component to call that RPC.

To call the ZxxxTT LIST RPC from your Delphi application to populate a list box:

  1. Place a TListBox component on your form. It should be automatically named ListBox1.
  2. Place a button beneath ListBox1.
  3. Double-click on the button. This creates an event handler procedure, TForm1.Button1Click, in your Pascal source code.

  4. In the TForm1.Button1Click event handler, add code to call the ZxxxTT LIST RPC and populate the list box with the retrieved list of terminal type entries. This code should:

    a. Set RCPBroker1's RemoteProcedure property to ZxxxTT LIST.

    b. Call RPCBroker1's Call method (in a try...except exception handler block) to invoke that RPC.

    c. Retrieve results from RPCBroker1's Results property, setting them one-by-one into the list box's Items property.

    This code should look as follows:

    Procedure TForm1.Button1Click(Sender: TObject);
    var
       i:integer;
    begin
      RPCBroker1.RemoteProcedure:='ZxxxTT LIST';
      try
        begin {call}
          RPCBroker1.Call;
          for i:=0 to (RPCBroker1.Results.Count-1) do
            ListBox1.Items.Add(piece(RPCBroker1.Results[i],'^',2));
        end; {call}
      except
        On EBrokerError do
          ShowMessage('A problem was encountered communicating with the server.');
      end; {try}

    end;

  5. Include the mfunstr unit in the Uses clause of your project's Pascal source file. This enables your application to use the piece function included in mfunstr.

  6. Your user account must have XUPROGMODE key assigned. This allows your application to execute any RPC, without the RPC being registered. Later in the tutorial you will register your RPCs.

  7. Now run your application, and press the Retrieve Terminal Types button. It should retrieve and display terminal type entries, and appear as follows:

Now that you can retrieve a list of terminal type entries, the next logical task is to retrieve a particular entry when a user selects that entry in the list box.