相关资料:
https://www.cnblogs.com/760044827qq/p/3790666.html
https://www.cnblogs.com/yangxuming/p/9181849.html
代码如下:
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;
注意:
//As用于将一个对象转换为另一个对象
procedure BtnClick(Sender:TObject);
begin
(Sender as TButton).Caption := 'Clicked';
end;
//对于对象填充接口的转换, 必须用As进行
(HTTPRIO as IExp).GetConnection;
//As不能用于数据类型的转换, 下面的代码是错误的:
var
i: Integer;
s: string;
begin
s := (i as string);
end;
//正确写法是:
s := string(i);