清空PageControl页上所有控件的值var
  i:Integer;
begin
  begin
    if rztbsht.Controls[i].ClassType = TcxTextEdit then
    begin
      (rztbsht.Controls[i] as TcxTextEdit).Text := '';
    end;
    if rztbsht.Controls[i].ClassType = TcxComboBox then
    begin
      (rztbsht.Controls[i] as TcxComboBox).ItemIndex := -1;
    end;
    if rztbsht.Controls[i].ClassType = TcxMemo then
    begin
      (rztbsht.Controls[i] as TcxMemo).Text:='';
    end;
  end;end;
但是清空不了。是不是我写法有问题?

解决方案 »

  1.   

    试下这样:var
      i:Integer;
    begin
      for i:= 0 to rztbsht.ControlCount - 1 do
      begin
        if rztbsht.Controls[i].ClassType = TcxTextEdit then
        begin
          (rztbsht.Controls[i] as TcxTextEdit).Text := '';
        end;
        if rztbsht.Controls[i].ClassType = TcxComboBox then
        begin
          (rztbsht.Controls[i] as TcxComboBox).ItemIndex := -1;
          (rztbsht.Controls[i] as TcxComboBox).Text := -1;
        end;
        if rztbsht.Controls[i].ClassType = TcxMemo then
        begin
          (rztbsht.Controls[i] as TcxMemo).Text:='';
        end;
      end;
    end;
      

  2.   

    还不行的话就试下这样,换成Components:var
      i:Integer;
    begin
      for i:= 0 to rztbsht.ComponentCount - 1 do
      begin
        if rztbsht.Components[i].ClassType = TcxTextEdit then
        begin
          (rztbsht.Components[i] as TcxTextEdit).Text := '';
        end;
        if rztbsht.Components[i].ClassType = TcxComboBox then
        begin
          (rztbsht.Components[i] as TcxComboBox).ItemIndex := -1;
          (rztbsht.Components[i] as TcxComboBox).Text := -1;
        end;
        if rztbsht.Components[i].ClassType = TcxMemo then
        begin
          (rztbsht.Components[i] as TcxMemo).Text:='';
        end;
      end;
    end;
      

  3.   

    for J:=0 to Pred(PageControl1.PageCount) do
    begin
      rztbsht := PageControl1.Pages[J];
      for I:=0 to Pred(rztbsht.ControlCount) do
      begin
        ...
      end
    end