FocusF.pas
资源名称:delphi.rar [点击查看]
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:1k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit FocusF;
- interface
- uses
- SysUtils, Windows, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, ComCtrls;
- type
- TFocusForm = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- EditFirstName: TEdit;
- EditLastName: TEdit;
- EditPassword: TEdit;
- StatusBar1: TStatusBar;
- procedure GlobalEnter(Sender: TObject);
- procedure EditFirstNameExit(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FocusForm: TFocusForm;
- implementation
- {$R *.DFM}
- procedure TFocusForm.GlobalEnter(Sender: TObject);
- var
- I: Integer;
- begin
- for I := 0 to ControlCount - 1 do
- // if the control is a label
- if (Controls [I] is TLabel) and
- // and the label is connected to the current edit box
- (TLabel(Controls[I]).FocusControl = Sender) then
- // copy the text leaving off the initial & character
- StatusBar1.SimpleText := 'Enter ' +
- Copy (TLabel(Controls[I]).Caption, 2, 1000);
- end;
- procedure TFocusForm.EditFirstNameExit(Sender: TObject);
- begin
- if EditFirstName.Text = '' then
- begin
- // don't let the user get out
- EditFirstName.SetFocus;
- MessageDlg ('First name is required',
- mtError, [mbOK], 0);
- end
- else if EditFirstName.Text = 'Admin' then
- begin
- // fill the second edit and jump to the third
- EditLastName.Text := 'Admin';
- EditPassword.SetFocus;
- end;
- end;
- end.