在Form的Object Inspector的Properties中有一个ActiveControl属性,
往Form里加上Button1那么ActiveControl的下拉菜单就有Button1,如果
再加上一个Button2,那么下拉菜单就有Buttton1和Button2了...如果自己写一个组件里面也要定义一个这样的属性,怎么来写(实现)呢?

解决方案 »

  1.   

    看了VCL源码没看出所以然,我只是看中ActiveControl那种动态的效果,不知道自己写一个这样的效果怎么实现?
      

  2.   

    procedure TCustomForm.SetActiveControl(Control: TWinControl);
    begin
      if FActiveControl <> Control then
      begin
        if not ((Control = nil) or (Control <> Self) and
          (GetParentForm(Control) = Self) and ((csLoading in ComponentState) or
            Control.CanFocus)) then
          raise EInvalidOperation.Create(SCannotFocus);
        FActiveControl := Control;
        if not (csLoading in ComponentState) then
        begin
          if FActive then SetWindowFocus;
          ActiveChanged;
        end;
      end;
    end;
    VCL里面的,自己模仿着做慢慢能行的
      

  3.   

    把那个属性定义为某个类应该就可以了。例如TButton,下拉时就会列出所有的按钮。
      

  4.   

    例如在一个包中,定义
    TTest = class(TComponent)
    private
      FNewProp: TButton;
    published
      property NewProp: TButton read FNewProp write FNewProp;
    end;