{*******************************************************} { } { Responsive Software http://www.responsive.co.nz } { } { Copyright (c) 2003-2006 Responsive Software Limited } { } {*******************************************************} unit ChooseString; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Base, Grids, StdCtrls, Buttons, DatabaseObjects; type TChooseStringForm = class(TBaseForm) CancelBitBtn: TBitBtn; OkBitBtn: TBitBtn; ListBox: TListBox; HeadingLabel: TLabel; procedure FormShow(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure ListBoxDblClick(Sender: TObject); private { Private declarations } public { Public declarations } StringChoice : string; function Choose (FormCaption : string; Heading : string; StringList : TStringList) : boolean; end; var ChooseStringForm: TChooseStringForm; implementation {$R *.dfm} function TChooseStringForm.Choose (FormCaption : string; Heading : string; StringList : TStringList) : boolean; begin Caption := FormCaption; HeadingLabel.Caption := Heading; ListBox.Clear; ListBox.Items.Assign(StringList); StringChoice := ''; Result := (ShowModal = mrOk); if Result then begin if (ListBox.ItemIndex >= 0) and (ListBox.ItemIndex < ListBox.Count) then StringChoice := ListBox.Items[ListBox.ItemIndex] else StringChoice := ListBox.Items[0]; end; end; procedure TChooseStringForm.FormShow(Sender: TObject); begin ListBox.SetFocus; end; procedure TChooseStringForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_ESCAPE then begin Close; Key := 0; end; end; procedure TChooseStringForm.ListBoxDblClick(Sender: TObject); begin ModalResult := mrOk; end; end.