delphi动态创建控件的例子


本文整理自网络,侵删。

 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
 
type
  TForm1 = class(TForm)
    pnl1: TPanel;
    btn1: TButton;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
  editm:array of tedit;
 
implementation
 
{$R *.dfm}
 
//动态创建EDIT控件
procedure TForm1.btn1Click(Sender: TObject);
var
    i,d,j:integer;
begin
d:=0; 
j:=3;
setlength(editm,j);
  for   i:=0   to   j-1   do
  begin
    editm[i]:=tedit.Create(self);
    editm[i].Parent:=pnl1;
    editm[i].Width:=120; 
    editm[i].Height:=20; 
    editm[i].Left:=0; 
    editm[i].Top:=0+d; 
    editm[i].Name:= 'edit'+inttostr(i);
    editm[i].Text:= 'edit'+inttostr(i);
    editm[i].Visible:=true; 
    d:=d+20; 
  end;
end;
//销毁创建的EDIT控件
procedure TForm1.btn2Click(Sender: TObject);
var
  i:Integer;
begin
for i:=0 to 2 do
begin
editm[i].free; 
end;
end;
 
end.

来源:https://www.cnblogs.com/onmyway20xx/articles/3626321.html

相关阅读 >>

Delphi新建服务,停止系统服务,以及获取服务状态和新建系统服务器的方法

Delphi使用hough变换查找直线

Delphi中转向语句break,continue,exit的作用

Delphi 15位身份证号码转18位身份证号码

Delphi listview用法

Delphi tstrings类的一些技巧

Delphi之如何快速开发原生activex控件

Delphi 数组竟然可以这样定义

Delphi ip地址转换str字符

Delphi firemonkey 学习笔记 �c tpopup 控件的使用

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...