zoukankan      html  css  js  c++  java
  • 教程-is与as的区别?

    相关资料:

    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);

  • 相关阅读:
    C#
    数据库SQL Server
    JavaScript题目
    vscode: Visual Studio Code 常用快捷键
    jQuery教程
    JavaScript快速排序
    JS编程艺术
    JS
    linux 笔记
    积累的各种资源
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/12856593.html
Copyright © 2011-2022 走看看