我的问题如同题目所说的那样!
比如我想控制一个控件的可用状态
 BitBtn1.Enabled:= True;
能没有什么函数可以达到这样的目的呢:
 Str1 := 'BitBtn1.Enabled := True';
 Fun(Str1)
我只是想知道能不能实现,如果可以怎么实现呢?谢谢了!

解决方案 »

  1.   

    如果你只是控制单独的按钮做法很简单:
    我给你举个例子,你修改就可以用了
    procedure TextClear(AForm:Tform);
    Var
      Index:integer;                      //序号
      IndexComponent:integer;             //控件序号
                                          //TDBEdit:             0
                                          //TwwDBLookupCombo:    1
                                          //TEdit:               2
                                          //TwwDBDateTimePicker: 3
                                          //TDBComboBox:         4
                                          //TDBMemo              5
      ComponentNameLength:integer;        //控件名称长度
      ComponentName:string;               //控件名称
      LastTwoString:string;               //后两位为cx
    begin
      for Index:=0 to AForm.ComponentCount-1 do
      begin
        if (Aform.Components[Index] is TComboBox) then
          if (Aform.Components[Index] as TComboBox).Enabled then
            (Aform.Components[index] as TComboBox).Text:='';
        if (Aform.Components[Index] Is TDBEdit) then
          if (Aform.Components[Index] as TDBEdit).DataField='' then
            (Aform.Components[Index] as TDBEdit).Text:='';  
        if (Aform.Components[Index] Is TEdit) then
          if (Aform.Components[Index] as TEdit).Enabled then
    (Aform.Components[Index] as TEdit).Text:='';
        if (Aform.Components[Index] Is TwwDBLookupCombo) then
          if (Aform.Components[Index] as TwwDBLookupCombo).DataField='' then
    (Aform.Components[Index] as TwwDBLookupCombo).Text:='';
        if (Aform.Components[Index] Is TwwDBDateTimePicker) then
          if (Aform.Components[Index] as TwwDBDateTimePicker).DataField='' then
          (Aform.Components[Index] as TwwDBDateTimePicker).Text:='';
        if (Aform.Components[Index] Is TwwDBComboBox) then
          if (Aform.Components[Index] as TwwDBComboBox).DataField='' then
          (Aform.Components[Index] as TwwDBComboBox).Text:='';
        if (Aform.Components[Index] Is TwwDBLookUpComboDlg) then
          if (Aform.Components[Index] as TwwDBLookUpComboDlg).DataField='' then
          (Aform.Components[Index] as TwwDBLookUpComboDlg).Text:='';
        if (Aform.Components[Index] Is TComboBox) then
        begin
          (Aform.Components[Index] as TComboBox).ItemIndex:=-1;
        end;
      end;
    end;
      

  2.   

    谢谢dickeybird888(于伟刚) 老兄,
    还有其它同志们有其它的方法吗?
      

  3.   

    我在Oracle8.05中也想要实现这样的功能,Delphi中的这样的功能我也想要.关注中!
      

  4.   

    //函数如下:
    function a1(str1:string);
    var
      index:integer;
    begin
      for Index:=0 to Form1.ComponentCount-1 do
      begin
        if (form1.Components[Index] Is TButton) then
          if (form1.Components[Index] as TButton).Name=str1 then
    (form1.Components[Index] as TButton).Enabled:=True;
      end;
    end;
    //你的程序的写法:  While not adoQuery1.eof then
      begin
         Str1 := adoQuery1.fields.FieldByName('MoKuai').asstring +
                 '.Enabled := True';
         a1(Str1);
        adoquery1.next;
      end;
      

  5.   

    你这基本上是编译原理了,等于自己做个解释器了,有点难。
    Str1 := 'BitBtn1.Enabled := True';
     Fun(Str1)
    你要分析你的字符串。但是做个通用的函数还是可以,但是你传的字符串要有规律。
    第一个字符串是对象,第二个是方法,最后才是值了,这个值就一定要事前知道是什么类型的值,比如是BOOLEAN,INTEGER,...的。
      

  6.   

    用我的方法可以实现。就是这个思路你的字符串要能知道True 是字符还是BOOLEAN的类型。函数在判断。比如可以写的这样
    'BitBtn1.Enabled := @boolean@True@';第1,2个@表示接下来的是boolean变量,2,3之间表示用字符表示的值
      

  7.   

    要编一个解SHI器或用脚本语句介入
      

  8.   

    大家能不能再讨论一下,将一个TreeView中的分支添加到另外一个TreeView中的对应父分支下去,也就是到相同的分支下,如果没有该父分支的话呢,自动建立一个相应的父分支!