is 与 as 运算符举例

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.

 
 
 
 
 

 

 
  

你可能感兴趣的:(is 与 as 运算符举例)