Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delphi - Creating custom frame with new event

I'm working on delphi XE2.
What I need:
I need MyFrame class with frame without any visible components, but with new event visible in Object Inspector. This event will inform my form (on which will be placed the MyFrame object), that f.e. all datas on the frame are fullfilled.

What I have:
Based on this post and the TOndrej's answer, and that hint, where Ba shows, that for XE2 we need to replace

delphivclide := GetModuleHandle('delphivclide160.bpl');

with this:

delphivclide := GetModuleHandle('vcldesigner160.bpl');

I have that code for new frame:

unit MyFrame;
interface
uses
  System.Classes, Vcl.Forms;
type
  TMyFrame = class(TFrame)
  private
  protected
    FOnFilledData : TNotifyEvent;
  public
  published
    property OnFilledData : TNotifyEvent read FOnFilledData write FOnFilledData;
  end;
implementation
end.

And that code for the registration unit:

unit MyFrameReg;
interface
procedure Register;

implementation
uses Windows, DesignIntf, Dialogs, wFrame;

procedure Register;
var
  delphivclide: THandle;
  TFrameModule: TCustomModuleClass;
begin
  delphivclide := GetModuleHandle('vcldesigner160.bpl');
  if delphivclide <> 0 then
  begin
    TFrameModule := GetProcAddress(delphivclide, '@Vclformcontainer@TFrameModule@');
    if Assigned(TFrameModule) then
    begin
      ShowMessage('I''m here');
      RegisterCustomModule(TMyFrame, TFrameModule);
    end;
  end;
end;
end.

When i'll build my package, I have the message I'm here, so i supossed, that the MyFrame is registered.

What is my problem:
Problem is, that it dosn't work to the end.
When I choose New VCL Application, and want to create MyFrame by choosing File -> New -> Other -> Delphi Projects -> MyFrame then apears strange window showed below.
When I select some directory there and click the OK button, the new Delphi project is closed and my package project is opened.

the window

I'll be very glad, if someone can advise me, what I've done wrong.

like image 791
Quasik Avatar asked Oct 31 '22 12:10

Quasik


1 Answers

A. Frame class registration

There is no need to do it in a "hacky way"

uses
...
  DMForm,
  VCLFormContainer,
...

procedure Register;
begin
...
  RegisterCustomModule(TYourFrameClass, TFrameModule);   // for frames
  RegisterCustomModule(TYourModuleClass, TDataModuleCustomModule);   // for data modules
...
end;

There is another way around to add frames too

type
  TNestableWinControlCustomModule = class (TWinControlCustomModule)
  public
    function Nestable: Boolean; override;
  end;

function TNestableWinControlCustomModule.Nestable: Boolean;
begin
  Result := True;
end;

+

  RegisterCustomModule(TYourFrameClass, TNestableWinControlCustomModule);

Names of units (tested in XE7):

TCustomModule => DesignEditors

TDataModuleCustomModule => DMForm (designide.dcp)

TWinControlCustomModule => WCtlForm (designide.dcp)

TFrameModule => VCLFormContainer (vcldesigner.dcp)

I suppose that for FireMonkey it should be possible in similar way (find fmxdesigner.dcp & check what is inside in Notepad++)

B. To use it inside "New..." wizard you need to register wizard class. If you don't have time to write wizard class just create new frame and then replace parent class name manually and add appropriate unit into "uses" list. That's all

PS. In older Delphi versions there was TDataModuleDesignerCustomModule metaclass instead of TDataModuleCustomModule in unit DMDesigner

PPS. Other existing metaclass names:

TCustomFormCustomModule

TIDESourceModuleCustomModule

like image 69
Mad Scientist Avatar answered Nov 15 '22 06:11

Mad Scientist