随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
  private
    procedure MyPro(Sender: TObject);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.OnClick := MyPro;
  Edit1.OnClick := MyPro;
end;

procedure TForm1.MyPro(Sender: TObject);
begin
  if Sender is TButton then
    ShowMessage((Sender as TButton).Caption);

  if Sender.InheritsFrom(TEdit) then
    ShowMessage((Sender as TEdit).Text);
end;

end.

posted on 2007-11-30 20:59  万一  阅读(...)  评论(...编辑  收藏