IDE: GotoLine dialog:

- restrict user input
- disable OK button if text is not a number

git-svn-id: trunk@60108 -
This commit is contained in:
bart 2019-01-19 15:45:35 +00:00
parent c3186f7af3
commit df0b4e4aa9
2 changed files with 24 additions and 1 deletions

View File

@ -9,7 +9,7 @@ object frmGoto: TfrmGoto
Caption = 'frmGoto'
ClientHeight = 101
ClientWidth = 250
LCLVersion = '0.9.29'
LCLVersion = '2.1.0.0'
object Label1: TLabel
Left = 6
Height = 14
@ -28,6 +28,8 @@ object frmGoto: TfrmGoto
Align = alTop
BorderSpacing.Around = 6
Constraints.MinWidth = 200
OnChange = Edit1Change
OnKeyPress = Edit1KeyPress
TabOrder = 0
Text = 'Edit1'
end
@ -38,11 +40,15 @@ object frmGoto: TfrmGoto
Width = 238
Align = alTop
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
HelpButton.Enabled = False
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CloseButton.Enabled = False
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 1
ShowButtons = [pbOK, pbCancel]
ShowBevel = False

View File

@ -36,6 +36,8 @@ type
ButtonPanel1: TButtonPanel;
Label1: TLabel;
Edit1: TEdit;
procedure Edit1Change(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: char);
public
constructor Create(AOwner: TComponent); override;
procedure DoShow; override;
@ -47,6 +49,19 @@ implementation
{ TfrmGoto }
procedure TfrmGoto.Edit1KeyPress(Sender: TObject; var Key: char);
begin
if not (UpCase(Key) in [#8,'0'..'9']) then
Key:=#0;
end;
procedure TfrmGoto.Edit1Change(Sender: TObject);
var
L: Integer;
begin
ButtonPanel1.OKButton.Enabled := TryStrToInt(Edit1.Text,L);
end;
constructor TfrmGoto.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
@ -56,12 +71,14 @@ begin
ButtonPanel1.OKButton.Caption:=lisMenuOk;
ButtonPanel1.CancelButton.Caption:=lisCancel;
Edit1.Caption := '';
Edit1.MaxLength := 10; //enough for MaxLongInt
end;
procedure TfrmGoto.DoShow;
begin
Edit1.SelectAll;
Edit1.SetFocus;
Edit1Change(nil);
inherited DoShow;
end;