Programação Em C++
Seminário: Programação Em C++. Pesquise 862.000+ trabalhos acadêmicosPor: jorgel13 • 30/1/2015 • Seminário • 429 Palavras (2 Páginas) • 167 Visualizações
Events are closures
C++Builder uses closures to implement events. A closure is a special pointer type
that points to a specific method in a specific class instance. As a component writer,
you can treat the closure as a place holder: your code detects that an event occurs, so
you call the method (if any) specified by the user for that event.
Closures maintain a hidden pointer to a class instance. When the user assigns a
handler to a component’s event, the assignment is not just to a method with a
particular name, but rather to a specific method of a specific class instance. That
instance is usually the form that contains the component, but it need not be.
All controls, for example, inherit a virtual method called Click for handling click
events:
virtual void __fastcall Click(void);
The implementation of Click calls the user’s click-event handler, if one exists. If the
user has assigned a handler to a control’s OnClick event, clicking the control results in
that method being called. If no handler is assigned, nothing happens
Events are closures
C++Builder uses closures to implement events. A closure is a special pointer type
that points to a specific method in a specific class instance. As a component writer,
you can treat the closure as a place holder: your code detects that an event occurs, so
you call the method (if any) specified by the user for that event.
Closures maintain a hidden pointer to a class instance. When the user assigns a
handler to a component’s event, the assignment is not just to a method with a
particular name, but rather to a specific method of a specific class instance. That
instance is usually the form that contains the component, but it need not be.
All controls, for example, inherit a virtual method called Click for handling click
events:
virtual void __fastcall Click(void);
The implementation of Click calls the user’s click-event handler, if one exists. If the
user has assigned a handler to a control’s OnClick event, clicking the control results in
that method being called. If no handler is assigned, nothing happens.
Events are properties
Components use properties to implement their events. Unlike most other properties,
events do not use methods to implement their read and write parts. Instead, event
...