Events with more parameters
You probably noticed that the OnChange
event only had one parameter, which was Sender
and is of the type Object
. Most of the time, this is adequate, but there may be times when we want to send other parameters into an event. In those cases, TNotifyEvent
is not an adequate type, and we will need to define a new type. The new type will need to be a method pointer type, which is similar to a procedural type but has the keyword of object
at the end of the declaration. In the case of TMessageLog
, we may need to perform some action before or after a message is written to the file. To do this, we will need to declare two method pointers, TBeforeWriteMsgEvent
and TAfterWriteMsgEvent
, both of which will be triggered in another method named WriteMessage
. The modification of our code will look as follows:
type TBeforeWriteMsgEvent = procedure(var Msg: String; var OKToWrite: Boolean) of Object; TAfterWriteMsgEvent = procedure(Msg: String) of Object; TmessageLog = class...