unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, ExtCtrls, Buttons;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    MaskEdit1: TMaskEdit;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    Panel1: TPanel;
    Shape1: TShape;
    Edit3: TEdit;
    Edit4: TEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label3: TLabel;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Label1Click(Sender: TObject);
    procedure KeyPressdlaEdit(Sender: TObject; var Key: Char);
    procedure Memo1DblClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var i:integer;
begin
  Label3.Caption:='';
  for i:=0 to ControlCount-1 do
    Label3.Caption:=Label3.Caption+IntToStr(i)+'  '+
                   Controls[i].Name+'  '+
                   Controls[i].ClassName+#13;
end;


procedure TForm1.BitBtn2Click(Sender: TObject);
var i:integer;
begin
  Label4.Caption:='';
  for i:=0 to ComponentCount-1 do
    Label4.Caption:=Label4.Caption+IntToStr(i)+'  '+
                   Components[i].Name+'  '+
                   Components[i].ClassName+#13;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
  for i:=0 to ControlCount-1 do
    if (Controls[i] is TEdit) then (Controls[i] as TEdit).Clear;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
  for i:=0 to ControlCount-1 do
    if (Controls[i] is TEdit) then //jesli kontrolka jest typu TEdit
     (Controls[i] as TEdit).Text:=IntToStr(Random(10));
end;

procedure TForm1.Label1Click(Sender: TObject);
begin
  if (Sender is Tlabel) then
    (Sender as TLabel).Visible:=false;
end;

//zmieniona zostala nazwa procedury z Edit1KeyPress na KeyPressdlaEdit
//nie kojarzy sie wtedy tylkio z Edit1
procedure TForm1.KeyPressdlaEdit(Sender: TObject; var Key: Char);
begin
  if (Sender is TEdit) then
    if not (Key in [#8,'0'..'9']) then Key:=#0;
end;

//procedura dziala dla komponentow pochodnych od klasy TCustomEdit
// np. TMemo, TEdit,TMaskEdit jesli zostala podpieta pod obsluge
//zdarzenia OnDoubleClick dla tych komponentow
procedure TForm1.Memo1DblClick(Sender: TObject);
begin
  if (Sender is TCustomEdit) then
    (Sender as TCustomEdit).Clear;
end;

procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
  Label3.Caption:='';
  for i:=0 to ControlCount-1 do
    Label3.Caption:=Label3.Caption+IntToStr(i)+'  '+
                   Controls[i].Name+'  '+
                   Controls[i].ClassName+#13;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   //te instrukcje są potrzebne do wyświetlenia napisu na przycisku w 2 wierszach
   //jeśli korzystamy z Delphi 7 w Windows XP
   BitBtn1.Caption:='Wyświetl numery,'+#13+'nazwy kontrolek'+#13+'oraz ich typy';
   BitBtn2.Caption:='Wyświetl numery,'+#13+'nazwy komponentów'+#13+'oraz ich typy';
end;

procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Sender is TShape) then
  begin
    (Sender as TShape).Brush.Color:=Random(9999999);
    (Sender as TShape).Shape:=TShapeType(Random(6));
  end;
end;

end.
