{*******************************************************} { } { Responsive Software http://www.responsive.co.nz } { } { Copyright (c) 2003-2006 Responsive Software Limited } { } {*******************************************************} unit PromptString; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Base, Grids, StdCtrls, Buttons; type TPromptStringForm = class(TBaseForm) OkBitBtn: TBitBtn; CancelBitBtn: TBitBtn; HeadingLabel: TLabel; StringEdit: TEdit; procedure FormShow(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure OkBitBtnClick(Sender: TObject); procedure StringEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } FForceEntry : boolean; public { Public declarations } Value : string; function Prompt (ForceEntry : boolean; FormCaption : string; HeadingLabelCaption : string) : boolean; end; var PromptStringForm: TPromptStringForm; implementation {$R *.dfm} function TPromptStringForm.Prompt (ForceEntry : boolean; FormCaption : string; HeadingLabelCaption : string) : boolean; begin FForceEntry := ForceEntry; Caption := FormCaption; HeadingLabel.Caption := HeadingLabelCaption; StringEdit.Text := ''; Result := (ShowModal = mrOk); end; procedure TPromptStringForm.OkBitBtnClick(Sender: TObject); begin Value := Trim(StringEdit.Text); end; procedure TPromptStringForm.FormShow(Sender: TObject); begin StringEdit.SetFocus; end; procedure TPromptStringForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_ESCAPE then begin Close; Key := 0; end; end; procedure TPromptStringForm.StringEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin if FForceEntry and (Trim(TEdit(Sender).Text) = '') then Exit; Value := Trim(StringEdit.Text); ModalResult := mrOk; Key := 0; end; end; end.