注册自定义框架 [英] Registering a custom Frame

查看:177
本文介绍了注册自定义框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi 2009中,在我的一个项目中,我有一个自定义框架,其中有一些控件,我想用作其他控件的基类。我想将此框架注册为IDE向导以在新建项目列表中可用。当我将新添加的项目(我的自定义框架)添加到项目中时,我希望它可以:


  1. 显示所有属性和事件I添加到对象检查器中的自定义框架。

  2. 从我的自定义框架而不是TFrame导出新创建的框架。

在Object Inspector中显示我的属性和事件,我将自定义模块注册到IDE中。它不适用于框架。幸运的是有人在StackOverflow上提及了这一点,并给出了一个答案:



显示TFrame后代的对象检查器的其他属性



然后,使其加载我的自定义框架的DFM,我添加了InitInheritedComponent到我的自定义框架的构造函数。这样的东西:

 构造函数TMyFrame.Create(AOwner:TComponent);覆盖
开始
被迫使用;
if(ClassType> TMyFrame)而不是(ComponentState中的csDesignInstance)然后
begin
如果不是InitInheritedComponent(Self,TMyFrame)然后
raise EResNotFound.CreateFmt('Resource %s not found',[ClassName]);
结束
结束

它不工作!它仍然在设计器中创建一个空框架,而不是我自己的框架。如果我没有将自定义模块注册到IDE中,即使不需要InitInheritedComponent也可以正确显示我的框架,但是如果我更改构造函数,则其他属性不会显示在Object Inspector!



来源(使用TFrame替换TMyFrame ):

 构造函数TMyFrame.Create(AOwner:TComponent) ;覆盖
开始
被迫使用;
if(ClassType> TFrame)而不是(ComponentState中的csDesignInstance)然后
begin
如果不是InitInheritedComponent(Self,TFrame)然后
raise EResNotFound.CreateFmt('Resource %s not found',[ClassName]);
结束
结束

框架正确添加到设计器中,其他属性在对象检查器中可见,但运行应用程序失败,因为它抱怨框架上的组件已经存在。



所以,我的问题是:有一个Delphi IDE向导的解决方案使用DFM从自定义框架(不是窗体)创建派生帧,并在对象检查器中显示其附加属性?



BTW,我不想在运行时在框架中构建控件,因为我需要它们在设计时可用。



我希望有人能让我清楚这一点。 p>

感谢



EDITED:



这些帧实际上用作向导组件的页面。我的向导组件在运行时创建它们。我希望用户在新建项目菜单中添加一个选项来添加一个向导页面进行项目设计,并在IDE设计器中设计其布局,并将其注册到向导组件中以显示。我从TFrame继承了一个基类,因为我的向导页面应该有一些必需的控件和一些自定义属性和事件。

解决方案

使用TFrames(及其相关的继承)作为组件开发的基础进行了相当广泛的探索,并且可以详细阐述我发现如果它是有用的,但是我从来没有需要使用RegisterCustomModule - 我只是从TFrames开发直接使用正常的帧继承,然后在标准组件注册单元中注册生成的最终版本。这似乎允许两个世界中最好的(视觉开发+继承,加上组件调色板+对象检查器功能)。



虽然有一些小小的技巧,并阻止观看,例如您如何命名TFrame本身,确保DFM文件在第一行正确使用对象或继承,并且通常我已经发现它非常有利于复杂继承树的稳定性,从而创建一个从TFrame继承的基本框架,但是对其添加了NOTH ...然后继承了所有其他的。 (添加已发布的属性时,这似乎尤其如此)。



更详细地介绍一下为什么要使用IDE向导,也许如果没有使用IDE向导在石头作为一种方法,我可以更多的帮助。


In Delphi 2009, In one of my projects, I have a custom frame with some controls on it which I want to use as the base class for some other controls. I want to register this frame as an IDE wizard to be available in New Items list. When I add my newly added item (my custom frame) to a project, I expect it to:

  1. Show all the properties and events I added to the custom frame in object inspector.
  2. Derive the newly created frame from my custom frame rather than TFrame.

Ok, to make it show my properties and events in Object Inspector, I register a custom module into IDE. It doesn't work properly for frames. Fortunately somebody mentioned this on StackOverflow, and an answer is given to this:

Showing TFrame descendant's additional properties on the object inspector

Then, to make it load DFM of my custom frame, I added InitInheritedComponent to the constructor of my custom frame. Something like this:

constructor TMyFrame.Create(AOwner: TComponent); override;
begin
  inerited;
  if (ClassType <> TMyFrame) and not (csDesignInstance in ComponentState) then
  begin
    if not InitInheritedComponent(Self, TMyFrame) then
      raise EResNotFound.CreateFmt('Resource %s not found', [ClassName]);
  end;
end;

It doesn't work! It still creates an empty frame in designer rather than my own frame. If I don't register custom module into IDE, it shows my frame correctly even without needing InitInheritedComponent, but additional properties are not shown in Object Inspector!

if I change constructor source to this (Replacing TMyFrame with TFrame):

constructor TMyFrame.Create(AOwner: TComponent); override;
begin
  inerited;
  if (ClassType <> TFrame) and not (csDesignInstance in ComponentState) then
  begin
    if not InitInheritedComponent(Self, TFrame) then
      raise EResNotFound.CreateFmt('Resource %s not found', [ClassName]);
  end;
end;

The frame is added to the designer correctly, and additional properties are visible in Object Inspector, but running the application fails, because it complains that the components on the frame already exist.

So, my question is: what is the solution for having a Delphi IDE wizard which creates a derived frame from a custom frame (not form) with DFM, and shows its additional properties in Object Inspector?

BTW, I don't want to build the controls in the frame at runtime, because I need them to be available in design time too.

I hope somebody can make this thing clear to me.

Regards

EDITED:

These frames are actually used as pages for a wizard component. My wizard component creates them at runtime. I want the user to have an option in "New Item" menu to add a wizard page to project, and design its layout in IDE designer, and register it with my wizard component to be shown in the wizard. I am inheriting a base class from TFrame because my wizard pages should have some mandatory controls and some custom properties and events.

解决方案

I have fairly extensively explored using TFrames (and their related inheritance) as a base for component development, and could elaborate on what I've found if it would be useful, but I have never had need of using RegisterCustomModule -- I just develop from TFrames directly, using normal frame inheritance, and then register the resulting "final" versions in a standard component registration unit. This seems to allow the best of both worlds (visual development + inheritance, plus component palette + object inspector capabilities).

There are a number of little tricks to it though, and snags to watch for, such as how you name the TFrame itself, making sure the DFM files use "object" or "inherited" properly on the first line, and, in general I have found it very beneficial for stability of complex inheritance trees to create a "base frame" that inherits from TFrame, but adds NOTHING to it... and then inherit all the others from there. (This seems particularly true when adding published properties etc).

Tell me more about why in particular you are wanting to use an IDE Wizard, and maybe if that is not cast in stone as an approach, I can be of more help.

这篇关于注册自定义框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆