Delphi - creating a custom frame with a new event

I am working on delphi XE2.
What I need:
I need a MyFrame class with a frame without any visible components, but with a new event visible in the Object Inspector. This event will inform my form (on which the MyFrame object will be placed), that is, fe all the data on the frame is filled.

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

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

with this:

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

I have this code for a 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 this 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 build my package, I have a message that I am here, so I frantically registered MyFrame.

What is my problem:
The problem is that it does not work to the end.
When I select New VCL Application and want to create MyFrame by choosing File β†’ New β†’ Other β†’ Delphi Projects β†’ MyFrame, a strange window will appear, shown below.
When I select a directory there and click OK, the new Delphi project closes and my package project opens.

the window

I will be very happy if anyone can advise me what I did wrong.

+5
source share
1 answer

a. Frame class registration

No need to do it in a "hacker way"

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

There is another way to add frames.

 type TNestableWinControlCustomModule = class (TWinControlCustomModule) public function Nestable: Boolean; override; end; function TNestableWinControlCustomModule.Nestable: Boolean; begin Result := True; end; 

+

  RegisterCustomModule(TYourFrameClass, TNestableWinControlCustomModule); 

Unit names (verified in XE7):

TCustomModule => DesignEditors

TDataModuleCustomModule => DMForm (designide.dcp)

TWinControlCustomModule => WCtlForm (designide.dcp)

TFrameModule => VCLFormContainer (vcldesigner.dcp)

I believe that for FireMonkey this should be possible in a similar way (find fmxdesigner.dcp and check what's inside in Notepad ++)

B. To use it in the "New ..." wizard , you need to register the wizard class. If you don’t have time to write a wizard class, simply create a new frame, and then manually replace the parent class name and add the corresponding block to the "uses" list. What all

PS. . In older versions of Delphi, instead of TDataModuleCustomModule in the DMDesigner module

was a metaclass TDataModuleDesignerCustomModule,

PPS Other existing metaclass names:

TCustomFormCustomModule

TIDESourceModuleCustomModule

+1
source

Source: https://habr.com/ru/post/1209211/


All Articles