首页 > 其他分享 >Delphi as 和 is 的使用

Delphi as 和 is 的使用

时间:2022-10-03 12:11:37浏览次数:75  
标签:begin end Sender Delphi TForm1 TObject 使用 TEdit

as就是把某个类型对象转换为某个指定类型,这样方便使用指定类型中的一些成员.
is就是判断某个对象是不是某个类型,可以筛选出我们需要的对象.

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to ControlCount - 1 do
  begin
    if Controls[i] is TEdit then
      if (Controls[i] as TEdit).Text <> '' then
      begin
        (Controls[i] as TEdit).Text := 'haha';
      end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 3 do
  begin
    TEdit(FindComponent('Edit' + IntToStr(i))).Text := 'hoho';
  end;
end;

end.

参考:https://www.cnblogs.com/jijm123/p/15292647.html

标签:begin,end,Sender,Delphi,TForm1,TObject,使用,TEdit
From: https://www.cnblogs.com/YXGust/p/16750269.html

相关文章