Jump to content
Henry Olive

Disable then Enable a Procedure

Recommended Posts

Good Day,

 

Procedure TForm1.MyProc;

begin

....

end;

 

TForm1..DBGrid2DblClick(Sender: TObject);
begin

  MyProc = Nil;  // i want to disable myproc  procedure, how?

  .......

  MyProc:=MyProc;  // i want to enable myproc  procedure, how?

end;

 

Thank You

 

Share this post


Link to post

it would be this?

 

private/public

TForm1.myproc(SenderTObject);

....

 

 

form1.dbgridDblClick := nil;

 

 

.... in another place

form1.dbgridDblClick := myproc;

 

Edited by programmerdelphi2k

Share this post


Link to post

or this:

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure OrThisProc(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TMyProcX = procedure(Sender: TObject);

var
  MyProcX: TMyProcX;
  MyProcY: TNotifyEvent;  // = procedure(Sender : TObject) of object;  <-- in this case, Object = Form1

procedure HelloWorld(Sender: TObject);
begin

end;

procedure TForm1.OrThisProc(Sender: TObject);
begin

end;


// to better understanding... it was edited:
begin
  // when it shouldnt be used
  MyProcX := nil;
  MyProcY := nil;

  // when, it should be...
  MyProcX := HelloWorld;
  MyProcY := OrThisProc;
  
  // before any use, test it
  if Assigned(MyProcX) then
    MyProcX(Sender);
  //
  if Assigned(MyProcY) then
    MyProcY(Sender);


end.

 

Edited by programmerdelphi2k

Share this post


Link to post

I think what you are looking for is this, declare a var to the type of the event.

procedure TfrmRTCaddie.LicenseEditRefresh(const AValid: boolean; AInvalidReason: string);
var
  ne: TNotifyEvent; //variable of event type
begin
  ne := edtLicKeyCode.OnChange; //set the variable to the current onchagne
  edtLicKeyCode.OnChange := nil; //set on change to nil
 //work goes here
 
  edtLicKeyCode.OnChange := ne;  //asign the event hander back to the control event
end;

 

Share this post


Link to post
TMyForm = Class(TForm)
strict private
  _doit: Boolean;
[...]


Procedure TMyForm.MyProc;
Begin
  If Not _doit Then
    Exit;

  [...]
End;

TForm1..DBGrid2DblClick(Sender: TObject);
Begin
  _doit := False;
  Try
    [...]
  Finally
    _doit := True;
  End;
End;

 

  • Like 1

Share this post


Link to post

using "conditionals" is going to make it very unsafe... any other method can undo... better "nil" ED, then nothing will happen! for sure!

 

NOTE: OF COURSE, ,any other method can UNdo it (nil...)  too... but this "way" is done by default when building your class on Delphi.

Edited by programmerdelphi2k

Share this post


Link to post
type TSomeProc = procedure of object;

TForm
private
  procedure DefProc;
public
  NullableProc: TSomeProc;
end

Form1.NullableProc := nil;
Form1.NullableProc := @DefProc;

 

Edited by Fr0sT.Brutal

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×