小弟想遍历一个application内的所有窗体和每个窗体内的控件的NAME,将所有的NAME都放到一个MEMO中,请问有什么办法可以做得到呢?万望各位大哥指点指点!

解决方案 »

  1.   

    //这是遍历自己的,如果是其他Appliaction还得用EnumWindows()、EnumChildWindows()
    ~~procedure TForm1.Button1Click(Sender: TObject);
      procedure pControlScan(mControl: TControl; mParentPath: string);
      var
        I: Integer;
      begin
        Memo1.Lines.Add(mParentPath + mControl.Name);
        if mControl is TWinControl then
          for I := 0 to TWinControl(mControl).ControlCount - 1 do
            pControlScan(TWinControl(mControl).Controls[I],
              mParentPath + mControl.Name + '.');
      end;
    var
      I: Integer;
    begin
      for I := 0 to Screen.FormCount - 1 do
        pControlScan(Screen.Forms[I], '');
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var I : integer;
    begin
      memo1.Lines.Clear;
      for I:= 0 to form1.ComponentCount-1 do
      begin
          memo1.Lines.Add(form1.Components[I].Name);
      end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var I : integer;
    begin
      memo1.Lines.Clear;
      for I:= 0 to form1.ComponentCount-1 do
      begin
          memo1.Lines.Add(form1.Components[I].Name);
      end;
    end;
    说得没错
      

  4.   

    var j:integer;
    begin
          for j:=0 to Frm.ComponentCount-1 do
          begin
             if Frm.components[j] is TFlatCheckBox then
             if  TFlatCheckBox(Frm.components[j]).tag=No then
             begin
                  if Flag then
                  begin
                   if not TFlatCheckBox(Frm.components[j]).checked then
                      TFlatCheckBox(Frm.components[j]).checked:=true;
                  end;
                  if not Flag then
                  begin
                   if TFlatCheckBox(Frm.components[j]).checked then
                     TFlatCheckBox(Frm.components[j]).checked:=false;
                  end;
             end;
          end;
    end;
      

  5.   

    这是遍历程序中所有窗体的一段程序请配合楼上47522341的程序
    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
    begin
      memo1.Lines.Clear;
      for i:=1 to application.ComponentCount-1 do
      begin
        if (application.Components[i] is Tform) then
          memo1.Lines.Add((application.Components[i] as Tform).Name);  end;
    end;
      

  6.   

    procedure FindComponents(hwnd:HWND;lParam:LPARAM);
    var
      szBuffer:Array[0..20] of char;
    begin
      GetWindowText(hwnd,szBuffer,20);
      ShowMessage(szBuffer);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      EnumChildWindow(Application.Handle,&FindComponents,20);
    end;