Delphi有没有悾件数组的概念,象VB那样。若有,怎么用?若您第一个回答正确,奉送50分

yuheng 2003-08-18 06:09:55
Delphi有没有悾件数组的概念,象VB那样。若有,怎么用?
...全文
100 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
susanxjuan 2003-08-19
  • 打赏
  • 举报
回复
好东东,我也一直有这个疑问。今天真是大开眼界
dawnxiao 2003-08-19
  • 打赏
  • 举报
回复
to PaPaCong(小勇)

什么意思??
PaPaCong 2003-08-19
  • 打赏
  • 举报
回复
var ed :array of [0..10] Tedit;
begin
ed[0]:=edit1;
edit[1]:=edit2;
。。。。
edit[10]:=edit10;

//可用循环处理 ,例如
for i:=0 to 10 do begin
ed[0].text:='hhhh';
end;
end;
dawnxiao 2003-08-19
  • 打赏
  • 举报
回复
private
{ Private declarations }
LabeledEditArray: array[1..5] of TLabeledEdit;
TempString: String;

procedure TFormMain.FormShow(Sender: TObject);
begin
LabeledEditArray[1] := LabeledEdit1 ;
LabeledEditArray[2] := LabeledEdit2 ;
LabeledEditArray[3] := LabeledEdit3 ;
LabeledEditArray[4] := LabeledEdit4 ;
LabeledEditArray[5] := LabeledEdit5 ;
TempString := '' ;
end;
dawnxiao 2003-08-19
  • 打赏
  • 举报
回复
//*************************************************************************
//使用过程的时候,需要将输入框控件输入框数组初始化
//输入框控件的tag属性需要设置,0代表代码型,1代表整数型,2代表小数型
//输入框的顺序需要用tab order进行顺序的预定义
//使用的时候将所有要控制的输入框的OnChange、OnEnter、OnKeyPress指向对应的过程
//*************************************************************************




//*************************************************************************
//本过程控制输入框按键
procedure TFormMain.LabeledEditKeyPress(Sender: TObject; var Key: Char);
var
i: integer;
begin
For i := 1 to 5 do
begin
if LabeledEditArray[i].Focused then
begin

//回车时焦点到下一个输入框
if key = #13 then Perform(WM_NEXTDLGCTL,0,0) ;

//代码型输入框
if LabeledEditArray[i].Tag = 0 then
begin
if not (key in [ '0'..'9' , 'a'..'z' , 'A'..'Z' , #8 ]) then key := #0 ;
end;

//整数型输入框
if LabeledEditArray[i].Tag = 1 then
begin
if not (key in [ '0'..'9' , #8 ]) then key := #0 ;
end;

//小数型输入框
if LabeledEditArray[i].Tag = 2 then
begin
if not (key in [ '0'..'9' , #46 , #8 ]) then key := #0 ;
end;

end;
end;
end;
//本过程控制输入框按键
//*************************************************************************




//*************************************************************************
//本过程控制输入框变化
procedure TFormMain.LabeledEditChange(Sender: TObject);
var
i,j: integer;
OKFlag: boolean;
m: integer;//整数部分位数
n: integer;//小数部分位数
SingleKey: Char;
begin
m := 6 ;
n := 4 ;
OKFlag := true ;
For i := 1 to 5 do
begin
if LabeledEditArray[i].Focused then
begin
//代码型输入框
if LabeledEditArray[i].Tag = 0 then
begin
For j := 1 to Length(LabeledEditArray[i].Text) do
begin
SingleKey := LabeledEditArray[i].Text[j];
if not (SingleKey in [ '0'..'9' , 'a'..'z' , 'A'..'Z' , #8 ]) then OKFlag := false;
end;
end;

//整数型输入框
if LabeledEditArray[i].Tag = 1 then
begin
For j := 1 to Length(LabeledEditArray[i].Text) do
begin
SingleKey := LabeledEditArray[i].Text[j];
if not (SingleKey in [ '0'..'9' , #8 ]) then OKFlag := false;
end;
end;

//小数型输入框
if LabeledEditArray[i].Tag = 2 then
begin
For j := 1 to Length(LabeledEditArray[i].Text) do
begin
SingleKey := LabeledEditArray[i].Text[j];
if not (SingleKey in [ '0'..'9' , #46 , #8 ]) then OKFlag := false;
end;

//小数点位置
if pos('.',LabeledEditArray[i].Text) <> 0 then
//有小数的情况
begin
//整数位数长度判断
if pos('.',LabeledEditArray[i].Text) - 1 > 6 then OKFlag := false ;

//小数位数长度判断
if Length(LabeledEditArray[i].Text) - pos('.',LabeledEditArray[i].Text) > n then OKFlag := false ;

//判断是否有两个小数点
if pos('.',copy(LabeledEditArray[i].Text,pos('.',LabeledEditArray[i].Text) + 1,Length(LabeledEditArray[i].Text) - pos('.',LabeledEditArray[i].Text))) <> 0 then OKFlag := false ;
end
else
//没有小数点的情况
begin
if Length(LabeledEditArray[i].Text) > m then OKFlag := false;
end;
end;

if OKFlag then
TempString := LabeledEditArray[i].Text
else
begin
LabeledEditArray[i].Text := TempString;
Keybd_event(VK_END,0, 0, 0);
Keybd_event(VK_END,0, KEYEVENTF_KEYUP, 0);
end;
end;
end;
end;
//本过程控制输入框变化
//*************************************************************************




//*************************************************************************
//本过程控制输入框获得焦点
procedure TFormMain.LabeledEditEnter(Sender: TObject);
var
i: integer;
begin
For i := 1 to 5 do
begin
LabeledEditArray[i].EditLabel.Font.Color := clBlack ;
LabeledEditArray[i].Font.Color := clBlack ;
if LabeledEditArray[i].Focused then
begin
TempString := LabeledEditArray[i].Text ;
LabeledEditArray[i].EditLabel.Font.Color := clBlue ;
LabeledEditArray[i].Font.Color := clBlue ;
end;
end;
end;
//本过程控制输入框获得焦点
//*************************************************************************
siwuge 2003-08-19
  • 打赏
  • 举报
回复
好文,帮顶。
97866 2003-08-19
  • 打赏
  • 举报
回复
var
A:array[1..5] of TEdit;
i:Integetr;
begin
for i:=1 to 5 do
begin
A[i]:=TEdit.create(self);
A[i].Parent:=Self;
A[i].Left:=10+i*2;
A[i].Text:='ArrayEdit'+IntToStr(i);
end;
End;
夜o猫 2003-08-19
  • 打赏
  • 举报
回复
VCL组件中都带有一个属性:ComPonents,用它就可以实现控件数组。

var
index:integer;
begin
for index:=0 to ControlCount-1 do
begin
if Components[index] is 类 then
begin
(components[index] as 类).相关操作
end;
end;
end;
charles2118 2003-08-19
  • 打赏
  • 举报
回复
当然有啊,
定义一个控件数组
var
EditArray:array of TEdit
begin
setlength(EditArray,theLengthYouWanted);
for i:=0 to setlength(EditArray,theLengthYouWanted)-1 do
begin
EditArray[i]:=TEdit.create(self);
with EditArray[i] do
begin
// 属性编写
top:=....
//事件编写
OnKeyPress:=...
end;
end;
注意事项,在定义它的top,height,left等属性时要小心设置,最好和i关联,不然会出现所有的edit重叠在一起,只见到一个的现象的
yuheng 2003-08-19
  • 打赏
  • 举报
回复
我指的是:在窗口内放置若干相同的悾件如:TEDIT,这些悾件基本上有相同的输入字符过滤功能如:只允许输入数字。能否象VB那样把他们作为一个悾件数组,只写一次鉴别程序?
yuheng 2003-08-19
  • 打赏
  • 举报
回复
我已另行开贴,请
bluecoffee1979(远程导弹) 97866(weiLuang) dawnxiao(曙光.net) PaPaCong(小勇)
来领分
vsice 2003-08-19
  • 打赏
  • 举报
回复
都说得差不多了吧。没啥讲的了
chenquan 2003-08-19
  • 打赏
  • 举报
回复
都说了哈,揭贴吧
boskey 2003-08-18
  • 打赏
  • 举报
回复
你指的会不会是Componets[]?
Cipherliu 2003-08-18
  • 打赏
  • 举报
回复
最重要的是TList.
gardenyang 2003-08-18
  • 打赏
  • 举报
回复
当然有了要不然objects是什么啊,tstringlist.objects,strings.objects都是啊
miszyf 2003-08-18
  • 打赏
  • 举报
回复
有,刚才的贴子有人答了

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧