首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

遍历两个panel上的控件,该如何处理

2012-03-31 
遍历两个panel上的控件遍历两个panel上的控件传入参数值为 0 时,遍历2个Panel传入参数值为 1 时,遍历1个Pa

遍历两个panel上的控件
遍历两个panel上的控件

传入参数值为 0 时,遍历2个Panel

传入参数值为 1 时,遍历1个Panel

怎么写一个通用的过程?

for i := 0 to Panel[i].ComponentCount - 1 do
  begin
  if Panel[i].Components[i] is Edit then begin
  if (Panel[i].Components[i] as Edit).Properties.ReadOnly = true then
  Edit(Self.Components[i] as TcxDBTextEdit).Properties.ReadOnly := False;
  end;
end;

//Panel[i] 类似

[解决办法]
begin、end没配对,勘正下:

Delphi(Pascal) code
procedure EComponents(const x:integer=0);var i,j:integer;    Panel:array of Tpanel;begin  setlength(Panel,2);  Panel[0]:=Form1.Panel1;//假定 Panel1 在 Form1 中  Panel[1]:=Form1.Panel2;//假定 Panel2 在 Form1 中  for j:=0 to 1-x do begin    for i := 0 to Panel[j].ComponentCount-1 do begin      if Panel[j].Components[i] is TEdit then begin        if (Panel[j].Components[i] as TEdit).Properties.ReadOnly then begin          //......        end;      end;    end;  end;end;
[解决办法]
参数改为TPanel,直接传Panel更好识别

Delphi(Pascal) code
procedure SetPnlCtrl(Pnl:TPanel);var i:integer;begin  for i := 0 to Pnl.ControlCount-1 do  begin    if Pnl.Controls[i] is Edit Then     begin      ...    end;  end;end; 

热点排行