Quantcast
Channel: TMS Software
Viewing all articles
Browse latest Browse all 1006

Friendly balloon hints for entry via TAdvInputTaskDialog

$
0
0


The TaskDialog API was introduced in the Microsoft Windows Vista operating system as a more user-friendly way to give notifications to users. Where a MessageBox() only has a caption, text, icon and buttons, the task dialog introduced additional expanded text, options to select from, checkbox to select to show the message again in the future or not etc...

When the Windows Vista TaskDialog appeared, TMS was the first to embrace it and make a component that not only used this API on Windows Vista or newer operating systems, but also emulated the API on operating systems older than Windows Vista so it would be useful everywhere opposed to applications using only the Microsoft API and thereby making the application minimum requirement Windows Vista or newer.

But we did not only that, we extended the capabilities offering that the dialog could also capture inputs rather than just show a message and wrapped this in the component TAdvInputTaskDialog. Inputs can be captured using various control types:

  • itEdit: regular TEdit is used
  • itMemo: regular TMemo is used
  • itComboEdit: a TComboBox in csDropDown style is used
  • itComboList: a TComboBox in csDropDownList style is used
  • itDate: a TDateTimePicker in dtkDate kind
  • itCustom: any custom VCL control can be used for input
  • itNone: no input is possible
  • itTime: a TDateTimePicker in dtkTime kind
  • itPassword: a TEdit with password style is used

And recently, we went a step further. We added a friendly way to validate input when the user wants to close the input dialog and show a Windows balloon hint with information when the input is not considered valid. To do this, implement the TAdvInputTaskDialog.OnValidateInputText() event handler. This event handler returns the entered text and has an IsValid parameter that can be used to allow the dialog to close or not. Now, with the properties AdvInputTaskDialog.InvalidEntryTitle, AdvInputTaskDialog.InvalidEntryText, AdvInputTaskDialog.InvalidEntryIcon we can specify what the balloon hint should display when the input is not considered valid.

How this works is shown in two samples below.
The first sample is for a capturing an email address with the validation that the user only enters a qualifying email address. We use the Delphi regular expressions component TRegEx to perform this validation and set the balloon hint info when the entry is not a valid email address:
procedure TForm1.Button1Click(Sender: TObject);
begin
  AdvInputTaskDialog1.Title := 'Enter email address';
  AdvInputTaskDialog1.Content := 'Email:';
  AdvInputTaskDialog1.Icon := tiShield;
  AdvInputTaskDialog1.ExpandedDefault := true;
  AdvInputTaskDialog1.ExpandedText := 'Your email address will be used to login';
  AdvInputTaskDialog1.Execute;
end;
procedure TForm1.AdvInputTaskDialog1ValidateInputText(Sender: TObject;
  var NewValue: string; const Data, ModalResult: Integer; var IsValid: Boolean);
begin
  isValid := TRegEx.IsMatch(NewValue, '^([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+).([a-zA-Z]{2,5})$');

  if not isValid then
  begin
    AdvInputTaskDialog1.InvalidEntryTitle := 'Input error';
    AdvInputTaskDialog1.InvalidEntryText := 'Value entered is not a valid email address';
    AdvInputTaskDialog1.InvalidEntryIcon := tieError;
  end;
end;


The second sample is for a capturing a password that needs to meet specific security requirements. As this concerns a password entry where the password is not supposed to be visible on the screen, the TAdvInputTaskDialog.InputType is set to itPassword. Also here we use the Delphi regular expressions component TRegEx to perform this validation and set the balloon hint info when the entry is not a valid email address:

procedure TForm1.Button2Click(Sender: TObject);
begin
  AdvInputTaskDialog2.Title := 'Enter a new password';
  AdvInputTaskDialog2.Content := 'Password:';
  AdvInputTaskDialog2.Icon := tiQuestion;
  AdvInputTaskDialog2.InputType := itPassword;
  AdvInputTaskDialog2.ExpandedDefault := true;
  AdvInputTaskDialog2.ExpandedText := 'The password must'#13
    + ' - have a lengh greater than or equal to 8'#13
    + '- contain one or more uppercase characters'#13
    + '- contain one or more lowercase characters'#13
    + '- contain one or more numeric values'#13
    + '- contain one or more special characters';

  AdvInputTaskDialog2.Execute;
end;
procedure TForm1.AdvInputTaskDialog2ValidateInputText(Sender: TObject;
  var NewValue: string; const Data, ModalResult: Integer; var IsValid: Boolean);
begin
  isValid := TRegEx.IsMatch(NewValue, '(?=^.{8,}$)(?=.*d)(?=.*[!@#$%^&*]+)(?![.
])(?=.*[A-Z])(?=.*[a-z]).*$');

  if not isValid then
  begin
    AdvInputTaskDialog2.InvalidEntryTitle := 'Invalid password';
    AdvInputTaskDialog2.InvalidEntryText := 'Please enter a password meeting the security requirements';
    AdvInputTaskDialog2.InvalidEntryIcon := tieError;
  end;
end;


TAdvInputTaskDialog with balloon hints is available in the latest TMS VCL UI Pack (the successor of TMS Component Pack) along with over 400 other powerful VCL user-interface components to make your Delphi Windows applications shine!

You can get the trial version to find out for yourself and note that when you are a student, we have a free academic version!


Viewing all articles
Browse latest Browse all 1006

Trending Articles