This is the only code that changes between the first and second code snippets: dlg.ShowModal(procedure(ModalResult: TModalResult) begin if ModalResult = mrOK then // if OK was pressed and an item is selected, pick it then edit1.Text := dlg.ListBox1.I…