我想通过查参数表对控件进行赋值,查询结果是控件名称和值,如何找到相应的控件,才能对其赋值?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    (FindChildControl( 'Button1' ) as TButton ).Caption:='hello world';
    end;
      

  2.   

    举个例子吧
    假如给控件名叫edit1的文本框赋值
    TEdit(FindComponent('edit1')).Text:='赋值';
      

  3.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      Comp: TComp;
    begin
      Comp := FindComponent('Button1');
      if (Comp <> nil) and (Comp is TButton) then
         TButton(Comp).Caption := 'Hello World';
    end;
      

  4.   

    特别提示: 在DLL 中 (Comp as TButton) 可能会报类转换错误, 但是 TButton(Comp)可能就不会. 在DLL中最好与不要用is 进行类型检测, 用if Comp.ClassName = TButton.ClassName then 比 if Comp is TButton then更好些.