写组件时,一般会用到这两个函数1 procedure RegisterComponents(const Page: string; const ComponentClasses: array of TComponentClass);
2 procedure RegisterNoIcon(const ComponentClasses: array of TComponentClass);函数1注册的一般会出现在面板上,如可视的TEdit,不可视的TMainMenu, TActionList
函数2注册的不会出现在面板上,如TMenuItem, TAction那么在运行时,能否用代码来判断某个组件是如何注册的
实际上我的想作一个窗体编辑器,RegisterComponents的非可视组件我需要显示,而RegisterNoIcon注册的组件不需要显示,所以我希望能判断一下以便我分别处理嗯,从是否TControl判断可能行不通,例如TActionList,TAction,TMenuItem,TMainMenu都不是TControl但Delphi的IDE会在设计窗体时,显示TActionList,TMainMenu,而不显示TAction,TMenuItem,请指教,谢谢

解决方案 »

  1.   

    稍稍在网上找了下资料,有一个思路供参考
    可以考虑使用 GExperts 
    http://www.gexperts.org/
    它有一个功能,可能得到delphi的菜单的中的Component的Configure Palette中所有可视控件图标
    在http://www.gexperts.org/otafaq.html的
    How can I paint the palette bitmap for a specific component
    我的思路是如果能得到图标的为可视控件,得不到的为非可视控件当然,它可能可以得到所有 palette 中控件名称,那就简单了,在palette 中的为可视控件,不在palette中的为非可视控件
    它支持从d6~d2010
      

  2.   

    谢谢,我猜测Gexperts的思路可能需要在IDE下才能工作,它用到的是ToolsAPI
    有朋友提示我看看Lazarus,不过它的机制和Delphi还是有所区别
    学习中
      

  3.   

    就是想区分可视和非可视的控件?
    根据有没有left/top属性行不行?
      

  4.   

    可视不可视是可以区分的,现在是将不可视中的两种情况进行区分
    另外,在组件面板上的不可视组件,保存在DFM中,都会保存一对left, top值,不过或许这也可以区分两种不可视组件
      

  5.   

    可视控件一般从TControl派生,不可视控件从TComponent派生
    但你要区分的并不是可视/不可视
      

  6.   

    RTTI看它从谁继承过来的,twincontrol肯定都可见的呀。
    不过兄弟你研究可够深度的啊。
      

  7.   


    这个也不确切,某些元件也只有left, top属性还有一种方式就是通过注册表来获得哪些元件是在元件板上的,不在的就是NoIcon的
      

  8.   

    這個問題跟你上次問的有點像...about.com有篇文章,說明了TActionList是如何創建出TAction或TDataSet如何創建TField,TField和TAction這兩者並沒有註冊在組建面板上面,如你說的RegisterNoIcon。從它的創建過程,或許可找出判斷方法,還有你上次的問題的答案!
    http://delphi.about.com/library/bluc/text/uc092501d.htm
      

  9.   

    参考这个http://blog.csdn.net/9913220/archive/2004/09/23/114095.aspx不过有点“后遗”症。:)
      

  10.   

    好资料,以前一直想研究PACKAGE这部分的元信息了,不过一直没开展。
      

  11.   

    拜读了JJWWANG的URL,可能文章中判断的还是可视与不可视,我要判断的是不可视中的两种情况,亦或我功力不足,没看明白,但仍然受到不少启发,正在开始看Avan_Lau提供的URL,再次谢谢两位及诸位同学
      

  12.   

    我发的链接只能过滤是不是 RegisterNoIcon注册的。DELPHI的文档中有下列内容可以参考
    A component can be almost any program element that you want to manipulate at design time. Creating a component means deriving a new class from an existing one. You can derive a new component in several ways:Modifying existing controls
    Creating windowed controls
    Creating graphic controls
    Subclassing Windows controls
    Creating nonvisual componentsThe following table summarizes the different kinds of components and the classes you use as starting points for each.Component creation starting points 
    To do this Start with this type
    Modify an existing component Any existing component, such as TButton or TListBox, or an abstract component type, such as TCustomListBox
    Create a windowed (or widget-based in CLX applications) control TWinControl (TWidgetControl in CLX applications)
    Create a graphic control TGraphicControl
    Subclassing a control Any Windows (VCL applications) or widget-based (CLX applications) control
    Create a nonvisual component TComponent
    You can also derive classes that are not components and cannot be manipulated on a form, such as TRegIniFile and TFont.
      

  13.   

    感觉 能在TFORM上设计,并且继承自TComponent但 not is TControl的都是不可视的。
      

  14.   

    JJ的文章中似乎是用自定义的过程拦截了,学习中,对Delphi的包机制了解极少,需要补课啊
      

  15.   

    Greatis Form Designer Pro 可能有点启发
      

  16.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
         public
        { Public declarations }
      end;var
      Form1: TForm1;  mycomps : tStringlist;
      mynoIcons : Tlist;implementation{$R *.dfm}
    // 测试注册代码
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      RegisterComponents('', [tbutton, tlabel]);
      RegisterNoIcon([tcheckbox, tedit]);
    end;
    // 注册控件过程
    procedure RegisterComponentsProc(const Page: string;
      const ComponentClasses: array of TComponentClass);
    var
      i:Integer;
    begin
      for i := low(ComponentClasses) to high(ComponentClasses) do
      begin       
        mycomps.AddObject(Page, TObject(ComponentClasses[i]));
      end;
    end;// 注册非可视控件过程
    procedure RegisterNoIconProc(
      const ComponentClasses: array of TComponentClass);
    var
      i:Integer;
    begin
      for i := low(ComponentClasses) to high(ComponentClasses) do
      begin
        mynoIcons.Add(ComponentClasses[i]);
      end;
    end;// 初始化
    initialization
      mycomps := tStringlist.Create;
      mynoIcons := Tlist.Create;
      classes.RegisterComponentsProc := RegisterComponentsProc;
      classes.RegisterNoIconProc := RegisterNoIconProc;// 析构
    finalization
      classes.RegisterComponentsProc := nil;
      classes.RegisterNoIconProc := nil;
      FreeAndNil(mycomps);
      FreeAndNil(mynoIcons);end.