RPC HELP Tutorial Tutorial Source Code
From VistApedia
Tutorial Source Code
unit tut1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Trpcb, RPCConf1, StdCtrls, MFunStr; type TForm1 = class(TForm) brkrRPCBroker1: TRPCBroker; ListBox1: TListBox; Button1: TButton; Name: TEdit; RightMargin: TEdit; FormFeed: TEdit; OpenExecute: TEdit; CloseExecute: TEdit; PageLength: TEdit; BackSpace: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure ListBox1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); private {Private declarations} public {Public declarations} // Added declaration of TermTypeList. TermTypeList: TStringList; end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); var ServerStr: String; PortStr: String; begin TermTypeList:=TStringList.Create; // Get the correct port and server from the Registry. if GetServerInfo(ServerStr,PortStr)<> mrCancel then begin {connectOK begin} brkrRPCBroker1.Server:=ServerStr; brkrRPCBroker1.ListenerPort:=StrToInt(PortStr); // Establish a connection to the RPC Broker server. try brkrRPCBroker1.Connected:=True; if not brkrRPCBroker1.CreateContext('ZxxxTT TERMTYPE') then Application.Terminate; except on EBrokerError do begin {error begin} ShowMessage('Connection to server could not be established!'); Application.Terminate; end; {error end} end; {try end} end else {connectOK end} Application.Terminate; end; procedure TForm1.Button1Click(Sender: TObject); var i: integer; begin brkrRPCBroker1.RemoteProcedure:='ZxxxTT LIST'; try begin {call begin} brkrRPCBroker1.Call; for i:=0 to (brkrRPCBroker1.Results.Count-1) do begin {copy begin} ListBox1.Items.Add(piece(brkrRPCBroker1.Results[i],'^',2)); // Added line. TermTypeList.Add(brkrRPCBroker1.Results[i]); end; {copy end} end; {call end} except on EBrokerError do begin ShowMessage('A problem was encountered communicating with the server.'); end; {try end} end; 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; procedure TForm1.FormDestroy(Sender: TObject); begin TermTypeList.Free; end; end.