當(dāng)前位置:首頁 > IT技術(shù) > Windows編程 > 正文

delphi 中 as 和 is 的使用
2021-09-16 11:44:50

as是把某個類型對象轉(zhuǎn)換成所需要的類型。

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
??????? if (Controls[i] as TEdit).Text <> '' then
??????? begin
??????????? (Controls[i] as TEdit).Text := 'haha';
??????? end;
?? end;
end;

end.

窗體控件

Tedit 1、Tedit 2、Tedit 3、Tbutton

本文摘自 :https://www.cnblogs.com/

開通會員,享受整站包年服務(wù)立即開通 >