Links
EControl Form Designer Pro
Registration Method Example

This example demonstrates how to register methods and event handlers 

 

Variant 1. Using MethRegister.AddMethod function

Step 1. 

Create event handler or appropriate method (with right signature), 

for example

procedure TForm1.User_ListViewCustomDraw(Sender: TCustomListView;
  const ARect: TRect; var DefaultDraw: Boolean);
begin
  //
end;

procedure TForm1.AnotherCustomDraw(Sender: TCustomListView;
  const ARect: TRect; var DefaultDraw: Boolean);
begin

 

Attention 

It is necessary to place those declarations in published or 'automatic' (where all form's field and methods is automatically added) section. 

 

Step 2. 

Somewhere in initialization code place MethRegister.AddMethod's calls

procedure TForm1.FormCreate(Sender: TObject);
begin
...
  MethRegister.AddMethod(GetTypeData(TypeInfo(TLVCustomDrawEvent)),
      Addr(TForm1.User_ListViewCustomDraw), Self);
  MethRegister.AddMethod(GetTypeData(TypeInfo(TLVCustomDrawEvent)),
      Addr(TForm1.AnotherCustomDraw), Self);
...
end;

 

Variant 2. Using Helper-functions

 

You can create helper functions for simple reuse of the same methods (with equal signature) 

 

Step 1. 

Create helper function for TLVCustomDrawEvent type

procedure AddCustomDrawEvent_Helper(ev: TLVCustomDrawEvent);
begin
 MethRegister.AddMethod(GetTypeData(TypeInfo(TLVCustomDrawEvent)), PMethod(@@ev)^);
end;

 

Step 2. 

Now you can register method with more intuitive way

procedure TForm1.FormCreate(Sender: TObject);
begin
...
  AddCustomDrawEvent_Helper(User_ListViewCustomDraw);
  AddCustomDrawEvent_Helper(AnotherCustomDraw);
...
end;

MethRegister object have a list of built-in helpers

  • procedure AddNotifyEvent(ev: TNotifyEvent);
  • procedure AddMouseEvent(ev: TMouseEvent);
  • procedure AddMouseMoveEvent(ev: TMouseMoveEvent);
  • procedure AddKeyEvent(ev: TKeyEvent);
  • procedure AddKeyPressEvent(ev: TKeyPressEvent);
  • procedure AddDragOverEvent(ev: TDragOverEvent);
  • procedure AddDragDropEvent(ev: TDragDropEvent);
  • procedure AddStartDragEvent(ev: TStartDragEvent);
  • procedure AddEndDragEvent(ev: TEndDragEvent);
  • procedure AddDockDropEvent(ev: TDockDropEvent);
  • procedure AddDockOverEvent(ev: TDockOverEvent);
  • procedure AddUnDockEvent(ev: TUnDockEvent);
  • procedure AddStartDockEvent(ev: TStartDockEvent);
  • procedure AddGetSiteInfoEvent(ev: TGetSiteInfoEvent);
  • procedure AddCanResizeEvent(ev: TCanResizeEvent);
  • procedure AddConstrainedResizeEvent(ev: TConstrainedResizeEvent);
  • procedure AddMouseWheelEvent(ev: TMouseWheelEvent);
  • procedure AddMouseWheelUpDownEvent(ev: TMouseWheelUpDownEvent);
  • procedure AddContextPopupEvent(ev: TContextPopupEvent);
Copyright (c) 2004 - 2011 EControl Ltd.. All rights reserved.
What do you think about this topic? Send feedback!