关于delphi的创建非可视组件的问题?
创建就是TComponent.Create(Self);具体的属性,方法之类的该怎么写呢??有大虾举个例子什么的吗?谢谢啦!...
创建 就是 TComponent.Create(Self);
具体的属性,方法之类的该怎么写呢??
有大虾举个例子什么的吗?谢谢啦! 展开
具体的属性,方法之类的该怎么写呢??
有大虾举个例子什么的吗?谢谢啦! 展开
2个回答
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure DeleteAllBn();
procedure BtnClick(Sender:TObject);
public
{ Public declarations }
Bn:array[0..30]of TButton;
BnCount:Integer;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DeleteAllBn();
var
ii:Integer;
begin
for ii:=0 to BnCount-1 do
begin
Bn[ii].Free;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteAllBn();
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ii,yy,ww:Integer;
begin
ww:=12;
yy:=45;
DeleteAllBn(); //释放资源
for ii:=0 to 9 do
begin
Bn[ii]:=TButton.Create(Form1);
Bn[ii].Parent:=Form1;
Bn[ii].OnClick:=BtnClick; //置响应函数
Bn[ii].Caption:=IntToStr(ii);
if((ww+Bn[ii].Width+5)>Width)then //根据窗口宽度布置按钮位置
begin
yy:=yy+Bn[ii].Height+5;
ww:=12;
end;
Bn[ii].Left:=ww;
Bn[ii].Top:=yy;
ww:=ww+Bn[ii].Width+5;
end;
BnCount:=10; //设置按钮个数
end;
procedure TForm1.BtnClick(Sender:TObject);
var
cn:TButton;
begin
cn:=TButton(Sender);
Edit1.Text:=cn.Caption;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ii,yy,ww:Integer;
begin
ww:=12;
yy:=45;
DeleteAllBn(); //释放资源
for ii:=0 to 25 do
begin
Bn[ii]:=TButton.Create(Form1);
Bn[ii].Parent:=Form1;
Bn[ii].OnClick:=BtnClick; //置响应函数
Bn[ii].Caption:=Char(Ord('A')+ii);
if((ww+Bn[ii].Width+5)>Width)then //根据窗口宽度布置按钮位置
begin
yy:=yy+Bn[ii].Height+5;
ww:=12;
end;
Bn[ii].Left:=ww;
Bn[ii].Top:=yy;
ww:=ww+Bn[ii].Width+5;
end;
BnCount:=26; //设置按钮个数
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure DeleteAllBn();
procedure BtnClick(Sender:TObject);
public
{ Public declarations }
Bn:array[0..30]of TButton;
BnCount:Integer;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DeleteAllBn();
var
ii:Integer;
begin
for ii:=0 to BnCount-1 do
begin
Bn[ii].Free;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteAllBn();
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ii,yy,ww:Integer;
begin
ww:=12;
yy:=45;
DeleteAllBn(); //释放资源
for ii:=0 to 9 do
begin
Bn[ii]:=TButton.Create(Form1);
Bn[ii].Parent:=Form1;
Bn[ii].OnClick:=BtnClick; //置响应函数
Bn[ii].Caption:=IntToStr(ii);
if((ww+Bn[ii].Width+5)>Width)then //根据窗口宽度布置按钮位置
begin
yy:=yy+Bn[ii].Height+5;
ww:=12;
end;
Bn[ii].Left:=ww;
Bn[ii].Top:=yy;
ww:=ww+Bn[ii].Width+5;
end;
BnCount:=10; //设置按钮个数
end;
procedure TForm1.BtnClick(Sender:TObject);
var
cn:TButton;
begin
cn:=TButton(Sender);
Edit1.Text:=cn.Caption;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ii,yy,ww:Integer;
begin
ww:=12;
yy:=45;
DeleteAllBn(); //释放资源
for ii:=0 to 25 do
begin
Bn[ii]:=TButton.Create(Form1);
Bn[ii].Parent:=Form1;
Bn[ii].OnClick:=BtnClick; //置响应函数
Bn[ii].Caption:=Char(Ord('A')+ii);
if((ww+Bn[ii].Width+5)>Width)then //根据窗口宽度布置按钮位置
begin
yy:=yy+Bn[ii].Height+5;
ww:=12;
end;
Bn[ii].Left:=ww;
Bn[ii].Top:=yy;
ww:=ww+Bn[ii].Width+5;
end;
BnCount:=26; //设置按钮个数
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询