Registering a custom Frame

vcldeveloper picture vcldeveloper · May 18, 2009 · Viewed 7.1k times · Source

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.

Answer

Jamo picture Jamo · Jun 2, 2009

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.