This example demonstrates how to register methods and event handlers
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;
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
Copyright (c) 2004 - 2011 EControl Ltd.. All rights reserved.
|
What do you think about this topic? Send feedback!
|