问:如何在DELPHI下根据字符串得到控件对象?
———————————————————————
以前在VB下我是这么做的。
dim control as control
set control=get_control("edit(1)")private function get_control(byval controlstring as string) as control
  control_split=split(controlstring,"(")
  select case trim(lcase(control_split(0)))
    case "edit"
      set get_control=edit(val(control_split(1)))
    case else
     .......
  end select
end function 
——————————————————————————
本人是一位DELPHI初学者,对DELPHI了解不多,故来请教DELPHI下怎么做到。
例如:如何根据字符串'edit1’或‘edit(1)'得到控件edit1或edit(1)对象。

解决方案 »

  1.   

    请遵循如下做法:
    先用RegisterClasses注册你想要创建的类。
    然后用FindClass返回你想要的类,再Create有一点必须注册,你的类比较继承自TPersistent
      

  2.   

    function TForm1.FindComponent(const Name: string): TComponent;
    var
      i: Integer;
    begin
      Result := nil;
      for i := 0 to ComponentCount-1 do
        if LowerCase(Components[i].Name) = LowerCase(Name) then
        begin
          Result := Components[i];
          Exit;
        end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      Edit: TEdit;
    begin
      Edit := TEdit(FindComponent('edit1'));
      if Edit <> nil then
        Edit.Text := 'i found you!';
    end;
      

  3.   

    用FindComponent都能解决问题了_____________________
    http://lysoft.7u7.net