Set B_ok.ModalResult
to mrOk
. (Delphi code given, as you included Delphi in the tags.)
Use if FormSelect.ShowModal = mrOk
to find out if the Ok
button was clicked. Read the FormSelect.CB_list.ItemIndex
to find out which value was chosen.
Or, better yet, give TFormSelect
a public property that contains the ItemSelected
. Set it to the CB_list.ItemIndex
in the B_ok.OnClick
event:
type
TFormSelect = class(TForm)
// other declarations
procedure B_okClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FItemSelected: Integer;
public
property ItemSelected: Integer read FItemSelected;
end;
implementation
procedure TFormSelect.B_okClick(Sender: TObject);
begin
FItemSelected := CB_list.ItemIndex;
end;
procedure TFormSelect.FormCreate(Sender: TObject);
begin
FItemSelected := -1;
end;
In the calling code:
SelectForm := TFormSelect.Create(nil);
try
if SelectForm.ShowModal = mrOk then
SelectedItem := SelectForm.ItemSelected;
finally
SelectForm.Free;
end;