Advertisement
HEX0x29A

Which edit selected?

Mar 18th, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.31 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Edit1: TEdit;
  12.     Button1: TButton;
  13.     Edit2: TEdit;
  14.     Button2: TButton;
  15.     Timer1: TTimer;
  16.     Panel1: TPanel;
  17.     Edit3: TEdit;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure Timer1Timer(Sender: TObject);
  20.   private
  21.     procedure SelectedEditEnter(Sender: TObject);
  22.     procedure SelectedEditExit(Sender: TObject);
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.dfm}
  33.  
  34. var
  35.   SelectedEdit: TEdit = nil;
  36.  
  37. procedure TForm1.SelectedEditEnter(Sender: TObject);
  38. begin
  39.   SelectedEdit := (Sender as TEdit);
  40. end;
  41.  
  42. procedure TForm1.SelectedEditExit(Sender: TObject);
  43. begin
  44.   SelectedEdit := nil;
  45. end;
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. var
  49.   i: Integer;
  50. begin
  51.   for i := 0 to Pred(ComponentCount) do
  52.     if Components[i].ClassName = 'TEdit' then
  53.     begin
  54.       (Components[i] as TEdit).OnEnter := SelectedEditEnter;
  55.       (Components[i] as TEdit).OnExit := SelectedEditExit;
  56.     end;
  57. end;
  58.  
  59. procedure TForm1.Timer1Timer(Sender: TObject);
  60. begin
  61.   if Assigned(SelectedEdit) then
  62.     Caption := SelectedEdit.Name
  63.   else
  64.     Caption := '';
  65. end;
  66.  
  67. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement