展开全部
as是把某个类型对象转换成所需要的类型。
is是判断某对象是否是某类型。
例如:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(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 //判断对象Controls[i]是否为TEdit类型
if (Controls[i] as TEdit).Text <> '' then //将对象Controls[i]转换成TEdit类型
begin
(Controls[i] as TEdit).Text := 'haha';//将对象Controls[i]转换成TEdit类型
end;
end;
end;
end.
窗体控件
Tedit 1、Tedit 2、Tedit 3、Tbutton
is是判断某对象是否是某类型。
例如:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(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 //判断对象Controls[i]是否为TEdit类型
if (Controls[i] as TEdit).Text <> '' then //将对象Controls[i]转换成TEdit类型
begin
(Controls[i] as TEdit).Text := 'haha';//将对象Controls[i]转换成TEdit类型
end;
end;
end;
end.
窗体控件
Tedit 1、Tedit 2、Tedit 3、Tbutton
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询