Henry Olive 5 Posted March 7, 2023 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
programmerdelphi2k 237 Posted March 7, 2023 (edited) it would be this? private/public TForm1.myproc(Sender: TObject); .... form1.dbgridDblClick := nil; .... in another place form1.dbgridDblClick := myproc; Edited March 7, 2023 by programmerdelphi2k Share this post Link to post
programmerdelphi2k 237 Posted March 7, 2023 (edited) 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 March 7, 2023 by programmerdelphi2k Share this post Link to post
SwiftExpat 65 Posted March 7, 2023 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
aehimself 396 Posted March 7, 2023 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; 1 Share this post Link to post
programmerdelphi2k 237 Posted March 7, 2023 (edited) 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 March 7, 2023 by programmerdelphi2k Share this post Link to post
Fr0sT.Brutal 900 Posted March 16, 2023 (edited) type TSomeProc = procedure of object; TForm private procedure DefProc; public NullableProc: TSomeProc; end Form1.NullableProc := nil; Form1.NullableProc := @DefProc; Edited March 16, 2023 by Fr0sT.Brutal Share this post Link to post