As already noted by Howard, the default event is defined by the ComponentEditor of the component. This field of Lazarus is not very well documented. But there are lots of examples in the official Lazarus sources: go to folder components/ideintf and open unit componenteditors.pas -- it implements the default component editor as well as some special component editors.
Navigating to
TDefaultComponentEditor I saw a property
BestEditEvent. This seems to be the default event. So, the task is to redefine the BestEdit event, and this will change the event which is created on a double-click on a control.
I managed to alter the default event of a TNotebook from OnBoundsChanged to OnResize by doing these steps
- Since I do not want to modify the LCL code with my example I create a new package and save it somewhere. Add package IDEIntf to the requirements in order to have access to all registration stuff and the default component editor. Of course, you can re-use the registration unit of your own package for this purpose.
- Add a new unit (named TestUnit here, but a better name should be more appropriate; of course you can also use the component unit or registration unit of your component).
- Add ComponentEditors to the interface "uses" and create a class which inherits from the ComponentEditor used by the component to be changed. In my case, this is TUntabbedNotebookComponentEditor, in other cases TDefaultComponentEditor is probably enough.
- Since TUntabbedNotebookComponentEditor does not have its own constructor, add a Create constructor and set "BestEditEvent" to the name of the event which will become the new default event -- as simple as that! BestEditEvent is a string.
- What's missing is registration of the new component editor (RegisterComponentEditor() ), and rebuilding the IDE
- After the next start of the IDE, the TNotebook inserts an OnResize event upon a double-click
Here is a copy of the simple unit, but the entire package code is also included in the attachment
unit TestUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, ComponentEditors;
type
TMyNotebookEditor = class(TUntabbedNotebookComponentEditor)
public
constructor Create(AComponent: TComponent;
ADesigner: TComponentEditorDesigner); override;
end;
procedure Register;
implementation
uses
ExtCtrls;
constructor TMyNotebookEditor.Create(AComponent: TComponent;
ADesigner: TComponentEditorDesigner);
begin
inherited;
BestEditEvent := 'OnResize';
end;
procedure Register;
begin
RegisterComponentEditor(TNotebook, TMyNotebookEditor);
end;
end.