type
{ TaxInputForm }
TaxInputForm = class(TForm)
private
Edit: TCustomEdit;
FNonChars: TCharSet;
procedure InputEditChange(Sender: TObject);
procedure InputEditKeyPress(Sender: TObject; var Key: Char);
protected
procedure Activate; override;
end;
// + the implementations
function axCreateInputDialog(OwnerForm: TCustomForm;
const ACaption, APrompt: string;
MaskInput: Boolean; NonChars: TCharSet;
const AMask: string; AEditClass: TEditClass;
var Value: string): TaxInputForm;
var Prompt: TLabel;
MinEditWidth: integer;
AMonitor: TMonitor;
begin
Result := nil;
Result := TaxInputForm(TaxInputForm.NewInstance);
Result.DisableAutoSizing;
Result.CreateNew(OwnerForm);
with Result do
begin
FNonChars := NonChars;
PopupMode := pmAuto;
BorderStyle := bsDialog;
Caption := ACaption;
Prompt := TLabel.Create(Result);
with Prompt do
begin
Parent := Result;
Caption := APrompt;
Align := alTop;
AutoSize := True;
end;
Edit := AEditClass.Create(Result);
with Edit do
begin
Parent := Result;
Top := Prompt.Height;
Align := alTop;
BorderSpacing.Top := 3;
AMonitor := _InputQueryActiveMonitor;
// check that edit is smaller than our monitor, it must be smaller at least
// by 6 * 2 pixels (spacing from window borders) + window border
MinEditWidth := Min(AMonitor.Width - 20,
Max(cInputQueryEditSizePixels,
AMonitor.Width * cInputQueryEditSizePercents div 100));
Constraints.MinWidth := MinEditWidth;
OnKeyPress := @Result.InputEditKeyPress;
OnChange := @Result.InputEditChange;
{$ifdef with_picedits}
if (AEditClass = TPxPicEdit) then
TPxPicEdit(Edit).ValueConstraints.PictureMask := AMask;
{$endif}
if (AEditClass = TMaskEdit) then
TMaskEdit(Edit).EditMask := AMask;
if (Value > '') then Text := Value;
TabStop := True;
if MaskInput then
begin
EchoMode := emPassword;
PasswordChar := '*';
end else
begin
EchoMode := emNormal;
PasswordChar := #0;
end;
TabOrder := 0;
end;
with TaxDlgBtnPnl.Create(Result) do
begin
Top := Edit.Top + Edit.Height;
Parent := Result;
ShowBevel := False;
ShowButtons := [pbOK, pbCancel];
Align := alTop;
end;
ChildSizing.TopBottomSpacing := 6;
ChildSizing.LeftRightSpacing := 6;
AutoSize := True;
InputEditChange(Edit);
// upon show, the edit control will be focused for editing, because it's
// the first in the tab order
Result.EnableAutoSizing;
end;
end;