请问:怎样查找一个指定名称的编辑框控件或下拉框控件,并返回该控件的值

解决方案 »

  1.   

    FindComponent(名字)————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        i: Integer;
    begin//查找名称为Edit1的编辑框
        for i := 0 to ComponentCount - 1 do
            if Components[i] is TEdit then
            begin
                if (Components[i] as TEdit).Name = 'Edit1' then
                begin
                    (Components[i] as TEdit).Text := 'Success!';
                    Abort;
                end;
            end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      str : string;
    begin
      str := 'Edit1';
      ShowMessage(TEdit(FindComponent(str)).Text);
    end;
      

  4.   

    或者
    procedure TForm1.Button1Click(Sender: TObject);
    var
      str : string;
    begin
      str := 'Edit1';
      ShowMessage(FormName(FindComponent(str)).Text);
    end;
      

  5.   

    AControl:=FindComponent(AName);
    if AControl is TComboBox then
      Result:=TComboBox(AControl).Text
    else if AControl is TEdit then
      Result:=TEdit(AControl).Text