如何在 Delphi Xe 中创建带有正则表达式掩码的输入对话框。例如只限制 3 个数字。
1 回答
3
Delphi 没有接受正则表达式 (regex) 作为输入掩码的文本输入。不过,您可以相当容易地做类似的事情。
创建您自己的表单,使用 a TMaskEditwith an EditMaskof000;1;_或TSpinEditset to a MinValueof 100and a MaxValueof 999。添加两个按钮(Ok和Cancel),分别ModalResult设置为mrOK和mrCancel。
添加一个属性来读取您使用的任何控件的值(StrToInt(MaskEdit1.Text);或SpinEdit1.Value),例如
property Value: Integer read GetValue;
GetValue很简单:
procedure TNumberInputForm.GetValue: Integer;
begin
Result := SpinEdit1.Value; // or Result := StrToInt(MaskEdit1.Text);
end;
然后使用代码:
Value := 0;
NumberInputForm := TNumberInputForm.Create;
try
if NumberInputForm.ShowModal = mrOK then
Value := FrmNumberInput.Value;
finally
NumberInputForm.Free;
end;
于 2013-06-17T18:10:18.250 回答