The delphi Procedure of Object (a special type of pointer) Theory: // adapted to implement a particular procedure or function is not a type TNotifyEvent = Procedure (Sender: TObject) of Object ; First: Procedure is the type of process can be understood as the type, parameters structure definition process, and the specific implementation may be dynamically assigned onclick example above: statement: onclick = procedure (Sender: TObject, a: Integer) of Object ; after that you can put TNotifyEvent as a process used, irrespective of its realization what features you want in onclik user what is written, is the same IF ASSIGN (onclick) the then onclick; so long as TNotifyEvent can be executed, the program went to execute it, the control is achieved events procedure pointer four bytes, stored in the address process. procedure of Object 8 bytes, and the address of the address classes save process procedure of Object is a class procedure (function class), used as follows: 1 , and normal function the same point: can be as general functions and procedures as in the instance of a class called as an object method; 2 , different from the ordinary functions: may not through the object, but by a direct call to the class. That is, the general functions and procedures must be invoked through instance (object) type, the process type (function class) may not necessarily be invoked by the instance of the class. Class by calling function or process, can be defined and implemented methods can not or is not suitable as a particular behavior of the object. Application: Delphi often seen in the following two definitions the Type TMouseProc = Procedure (X-, the Y: Integer); // a conventional process TMouseEvent = Procedure (X-, the Y: Integer) of Object; //A type of object methods both look about the same but the actual meaning is not the same, the difference lies in TMouseEvent type of approach must be a object. A hidden parameter based method has self, both the parameter that is not the same, it is not interchangeable. TMouseProc only a single function pointer type; TMouseEvent is a function pointer to the object, i.e. the object function / class / method of Procedure TForm1. the BBB (the I: Integer); the begin ShowMessage ( ' the BBB: ' + the IntToStr (the I)); End ; Procedure TForm1.CCC (the I: Integer); the begin ShowMessage ( ' the CCC: ' + the IntToStr (the I)); End ; Procedure TForm1.Button1Click (Sender: TObject); of the type TAAA = Procedure (I: Integer) of Object ; var ap: TAAA; the begin ap: = BBB; // There is an implicit Self, full format: self.BBB; where the method of assigning the BBB variable ap, attention BBB ap prototype and declared to be the same, otherwise there will be wrong ap ( 1 ); ap: = CCC; ap ( 2 ); End ; Unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AdvEdit; type TForm1 = class(TForm) edt1: TAdvEdit; edt2: TAdvEdit; btn1: TButton; procedure btn1Click (Sender: TObject); private { Private declarations } public procedure myonExit (sender: TObject); over ; was Form1: TForm1; implementation { $ R * .dfm } procedure TForm1.myonExit (sender: TObject); begin if tadvedit (transmitter) .text = ' a ' then begin Show Message ( ' a ' ); Over presence IFtadvedit (transmitter) .text = ' B ' then begin Show Message ( ' b ' ); over ; over ; procedure myonExit2 (sender: TObject); begin if tadvedit (transmitter) .text = ' c ' then begin Show Message ( ' C ' ); Over presence IF tadvedit (transmitter) .text = ' d ' then begin Show Message ( ' d ' ); over ; End ; Procedure TForm1.btn1Click (Sender: TObject); type X1 = Procedure (SENDER: TObject) of Object ; X2 = Procedure (SENDER: TObject); var Y1: X1; Y2: X2; the begin Y1: = myonExit; // with hidden Self = myonExit2;: Y2 // without hidden Self Y1 (edt1); // edt box is a pop-up message box a or b or b ; Y2 (edt1) // when c or d is a block edt pop-up message box c or d // edt1.OnExit: = myonExit; // use Not myonExit2 CAN End ; End .
delphi的procedure of object
Guess you like
Origin www.cnblogs.com/tobetterlife/p/12176941.html
Ranking