assign a procedure in a form to a notify event in delphi -


i trying assign procedure defined in form event onstatechange of datasource this:

unit sdimain;  interface  uses windows, ....., db ;  type    tsdiappform = class(tform)    ....    procedure datasourceonstatechange(sender: tobject);  private   statechange : tnotifyevent; ....  var   sdiappform: tsdiappform; ... end;  procedure tsdiappform.formcreate(sender: tobject); begin  datamodule1.adstable1.active := true;  datamodule1.adstable2.open; statechange := sdiappform.datasourceonstatechange(datamodule1.adstable1); datamodule1.datasource1.onstatechange := statechange;  . . . procedure tsdiappform.datasourceonstatechange(sender: tobject); begin...end; 

initially when tried doing above got error! incompatible types: 'tnotifyevent' , 'procedure, untyped pointer or untyped parameter'

i tried changing  statechange := sdiappform.datasourceonstatechange(datamodule1.adstable1); statechange := sdiappform.datasourceonstatechange;  don't error doesn't work. onstatechange event not fired @ all.  tried other methods using  var method : tmethod; . . . method.data := pointer(self); method.code := methodaddress('datasourceonstatechange'); , using pointers doesn't work. 

i'm new delphi , i'm learning. might have not understood supposed done. helpful if can me on problem.

thanks. 

assigning method datasourceonstatechange event of datamodule1.datasource1.onstatechange work:

   statechange := sdiappform.datasourceonstatechange;    datamodule1.datasource1.onstatechange := statechange; 

which written

datamodule1.datasource1.onstatechange := sdiappform.datasourceonstatechange; 

if not need statechange other purposes.

sdiappform.datasourceonstatechange(datamodule1.adstable1); 

is direct call of method datamodule1.adstable1 sender, not method self.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -