FocusF.pas
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:1k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit FocusF;
  2. interface
  3. uses
  4.   SysUtils, Qt, Classes, QGraphics, QControls,
  5.   QForms, QDialogs, QStdCtrls, QComCtrls, QExtCtrls;
  6. type
  7.   TFocusForm = class(TForm)
  8.     Label1: TLabel;
  9.     Label2: TLabel;
  10.     Label3: TLabel;
  11.     EditFirstName: TEdit;
  12.     EditLastName: TEdit;
  13.     EditPassword: TEdit;
  14.     StatusBar1: TStatusBar;
  15.     procedure GlobalEnter(Sender: TObject);
  16.     procedure EditFirstNameExit(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22. var
  23.   FocusForm: TFocusForm;
  24. implementation
  25. {$R *.xfm}
  26. procedure TFocusForm.GlobalEnter(Sender: TObject);
  27. var
  28.   I: Integer;
  29. begin
  30.   for I := 0 to ControlCount - 1 do
  31.     // if the control is a label
  32.     if (Controls [I] is TLabel) and
  33.       // and the label is connected to the current edit box
  34.       (TLabel(Controls[I]).FocusControl = Sender) then
  35.     // copy the text leaving off the initial & character
  36.     StatusBar1.SimpleText := 'Enter ' +
  37.       Copy (TLabel(Controls[I]).Caption, 2, 1000);
  38. end;
  39. procedure TFocusForm.EditFirstNameExit(Sender: TObject);
  40. begin
  41.   if EditFirstName.Text = '' then
  42.   begin
  43.     // don't let the user get out
  44.     EditFirstName.SetFocus;
  45.     MessageDlg ('First name is required',
  46.       mtError, [mbOK], 0);
  47.   end
  48.   else if EditFirstName.Text = 'Admin' then
  49.   begin
  50.     // fill the second edit and jump to the third
  51.     EditLastName.Text := 'Admin';
  52.     EditPassword.SetFocus;
  53.   end;
  54. end;
  55. end.
  56.