Callback function and Delphi's event model Callback function: The callback function is a mechanism in which the caller passes some parameters to the object when initializing an object (the object here refers to objects in OOP, global functions, etc.) , while passing a function address that the caller can access to the object. This function is a notification agreement between the caller and the callee. When the agreed event occurs, the callee (usually including a working thread) will call the function according to the callback function address. This way, the caller is in one thread and the callee is in another thread. There are some functions in the Windows API that use callback functions, such as CreateThread, SetWindowLong, etc. The corresponding callback function is defined in the following form: function CallBackFunc(Wnd: HWND; Msg, WParam, LParam: Longint): Longint;stdcall;PRocedure ThreadFunction(Ptr: Pointer); stdcall; Message: Message can also be regarded as some form of callback, because the message is also passed by the caller to the callee during initialization. A handle and a message number are passed to the callee when the agreed event occurs. The caller sends the message. In this way, the caller is in the main thread and the callee is in the main thread or worker thread. Delphi event model: Many visual components in Delphi's VCL use event models, such as TForm's OnCreate event. The principle is: specify the event function at design time, and when the event is triggered at runtime, the function specified at design time will be called. event function. Mechanically, the Delphi event model is the same as callbacks. But there are some differences in the specific forms. A pure callback function is in the form of a global function, while a Delphi event is in the form of an object method. That is, the following callback function type can be defined: typeTCallBackFunc = procedure (pData: Pointer) of object; This makes the Delphi event only Used internally in Delphi, the callback function is cross-language. Also note that the callback function is generally a thread created in the callback body (components in Delphi are in the main thread), so critical section protection is required.