as就是把某个类型对象转换为某个指定类型,这样方便使用指定类型中的一些成员.

is就是判断某个对象是不是某个类型,可以筛选出我们需要的对象.

下面是一个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
procedure DoEdit(Sender: TObject);
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';
(Controls[i] as TEdit).OnClick:= DoEdit;
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; procedure TForm1.DoEdit(Sender: TObject);
begin
ShowMessage((Sender as TEdit).Name);
end; end.

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

Delphi as 和 is 的使用的更多相关文章

  1. 学习笔记:7z在delphi的应用

    最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...

  2. delphi连接sql存储过程

    针对返回结果为参数的 一. 先建立自己的存储过程 ALTER PROCEDURE [dbo].[REName] ) AS BEGIN select ROW_NUMBER() over(order by ...

  3. delphi 2010与delphi XE破解版的冲突

    在系统中同时安装了Dephi 2010LITE版与Delphi XE lite后,总是会有一个有问题 是因为两者都是读取C:\ProgramData\Embarcadero目录下的license文件, ...

  4. [Delphi] Delphi版本号对照

    VER300    Delphi Seattle / C++Builder Seattle    23    230    (Delphi:Win32/Win64/OSX/iOS32/iOS64/An ...

  5. delphi tidhttp 超时设置无效的解决方法

    现在delphi都发布到xe8了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTimeout ...

  6. Delphi Code Editor 之 编辑器选项

    Delphi Code Editor 之 编辑器选项 可从Code Editor的右键菜单中选择“Properties”菜单项来查看编辑器选项.也可以从主菜单[Tools | Editor Optio ...

  7. Delphi使用ADO进行数据库编程

    Delphi是一个可视化的编程工具,ADO编程也是这样,所以话不多言,直接通过代码.截图和语言来说明. 我的数据库是Oracle,为了测试,先建一个表:create table practice(un ...

  8. 怎么使用Delphi获取当前的时间,精确到毫秒

    先介绍一个可能比较常用的方法,获取当前时间 var datetime: string; begin datetime:= FormatDateTime('yyyy-mm-dd hh:mm:ss', N ...

  9. Delphi在创建和使用DLL的时候如果使用到string,请引入ShareMem单元

    当使用了长字符串类型的参数.变量时,如string,要引用ShareMem. 虽然Delphi中的string功能很强大,但若是您编写的Dll文件要供其它编程语言调用时,最好使用PChar类型.如果您 ...

  10. Delphi控件之---通过编码学习TStringGrid(也会涉及到Panel控件,还有对Object Inspector的控件Events的介绍

    我是参考了万一的博客里面的关于TStringGrid学习的教程,但是我也结合自己的实际操作和理解,加入了一些个人的补充,至少对我有用! 学用TStringGrid之——ColCount.RowCoun ...

随机推荐

  1. CSS动画,盒子爬坡源码

    html: <!DOCTYPE html> <html lang="en"> <head>     <meta charset=" ...

  2. Philips and Calculator

    代码 #include<cstdio> #include<algorithm> using namespace std; const int N = 3 * 1e6; int ...

  3. 最大K段和

    题目大意 有一个长度为 \(N\) 的序列 \(A\) .他希望从中选出不超过 \(K\) 个连续子段,满足它们两两不相交,求总和的最大值(可以一段也不选,答案为 \(0\)). 分析 很容易想到 \ ...

  4. 依那西普减量维持过程中RA病人自报病情复发可能预示未来放射学进展[EULAR2015_SAT0147]

    依那西普减量维持过程中RA病人自报病情复发可能预示未来放射学进展   SAT0147 SELF-REPORTED FLARES PREDICT RADIOGRAPHIC PROGRESSION IN ...

  5. IIS 负载均衡(ARR)

    Application Request Route:应用程序请求路由 1.下载安装web平台安装程序 微软官网搜索 "web平台安装程序" 只能找到 "web平台安装程序 ...

  6. LeetCode-593 有效的正方形

    来源:力扣(LeetCode)链接:https://leetcode.cn/problems/valid-square 题目描述 给定2D空间中四个点的坐标 p1, p2, p3 和 p4,如果这四个 ...

  7. mybatis:自定义映射关系resultMap

    创建表t_emp 定义实体类 package org.example.entity; public class Emp { private Integer empId; private String ...

  8. Spring、SpringMVC的区别

    Spring是IOC和AOP的容器框架,SpringMVC是基于Spring功能之上添加的Web框架,想用SpringMVC必须先依赖Spring.简单点的话可以将SpringMVC类比于Struts ...

  9. Python3 时间戳格式化和减法运算

    import datetime import time # 获取当前时间(2023-02-16 16:41:36) now_date = datetime.datetime.now().strftim ...

  10. 使用git cz 时报模块找不到 使用commitizen init cz-conventional-changelog --save --save-exact --force 又报下面错 头晕

    使用git cz 时报模块找不到 使用commitizen init cz-conventional-changelog --save --save-exact --force 又报下面错 头晕 At ...