Board index » delphi » How enable/disable a method

How enable/disable a method

Hello !!

I have written a code for the method: Datamodule1.Table1.BeforePost
But, sometimes I do not want that this method works.
I have tried with  Datamodule1.Table1.BeforePost:= nil and It works. But
then, the Datamodule1.Table1.BeforePost method do not work any more.

How can I enable/disable a method?

How can I enable the method after do Datamodule1.Table1.BeforePost:=
nil?

Thank You very much !!

(sorry, if my english it is no good)

 

Re:How enable/disable a method


Hi Jose,
just store the old event value into some variable and set event to nil.
later you can REenable the event by restoring its original value:

Var OldBeforepost: tdatasetNotifyEvent;
begin
  OldBeforepost := Datamodule1.Table1.BeforePost;
  Datamodule1.Table1.BeforePost := NIL;
  .........
  Datamodule1.Table1.BeforePost := OldBeforePost;
end;

IMHO,  better approach would be to declare a flag that  should
be checked within the event body:

Datamodule1.Table1BeforePost(...)
begin
  if not IgnoreBeforePost then begin
   ...... Before post event body ......
  end;
end;
--
Roman
I...@rksolution.cz (please remove STOPSPAM. in header)
Delphi corner now open at my website http://www.rksolution.cz

Quote
Jose Luis Garcia wrote in message <35AE34E9.B9B2F...@teleline.es>...
>Hello !!

>I have written a code for the method: Datamodule1.Table1.BeforePost
>But, sometimes I do not want that this method works.
>I have tried with  Datamodule1.Table1.BeforePost:= nil and It works. But
>then, the Datamodule1.Table1.BeforePost method do not work any more.

>How can I enable/disable a method?

>How can I enable the method after do Datamodule1.Table1.BeforePost:=
>nil?

>Thank You very much !!

>(sorry, if my english it is no good)

Other Threads