When a user selects a terminal type entry in the list box, a typical action would be to retrieve the corresponding record and display its fields. The key to retrieving any VA FileMan record is knowing the ien of the record. So when a user selects an entry in the list box, you need to know the ien of the corresponding VA FileMan entry. However, the list box items themselves only contain the name of each entry, not the ien.
The subscripting of items in the list box still matches the original subscripting of items returned in RPCBroker1's Results property, as performed by the following code in Button1Click event handler:
for i:=0 to (RPCBroker1.Results.Count-1) do
ListBox1.Items.Add(piece(RPCBroker1.Results[i],'^',2));
If no further calls to RPCBroker1 were made, you could simply refer back to RPCBroker1's Results[x] item to obtain the matching ien of a list boxes' Items[x] item. But, since RPCBroker1 will be used again, the Results property will be cleared. So the results must be saved off in another location, if you want to be able to refer to them after other Broker calls are made.
To save off the Results to another location:
type
TForm1 = class(TForm)
RPCBroker1: TRPCBroker;
ListBox1: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
TermTypeList: TStrings; // Added declaration of TermTypeList
end;
TermTypeList:=TStringList.Create;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
RPCBroker1.RemoteProcedure:='Zxxx LIST';
try
begin {call}
RPCBroker1.Call;
for i:=0 to (RPCBroker1.Results.Count-1) do begin {copy}
ListBox1.Items.Add(piece(RPCBroker1.Results[i],'^',2));
TermTypeList.Add(RPCBroker1.Results[i]); //added line
end; {copy}
end; {call}
except
On EBrokerError do
ShowMessage('A problem was encountered communicating with the server.');
end; {try}
end;
procedure TForm1.FormDestroy(Sender: TObject); begin TermTypeList.Free; end;
Then, to determine (and display) the ien of the corresponding terminal type when a user selects an item in the list box:
procedure TForm1.ListBox1Click(Sender: TObject);
var
ien: String;
begin
if (ListBox1.ItemIndex <> -1) then
begin {displayitem}
ien:=piece(TermTypeList[ListBox1.ItemIndex],'^',1);
ShowMessage(ien);
end; {displayitem}
end;
Now that you can determine the ien of any entry the user selects in the list box, you can retrieve and display the corresponding VA FileMan record for any selected list box entry.