Podstrony
- Strona startowa
- Bruce Morris Adventure Guide Florida Keys & Everglades National Park (2005)
- The Career Survival Guide Dealing with Office Politics Brian OÂ’Connell
- (Ross Enamait) The Underground Guide To Warrior Fitness
- Novell Netware 5 Advanced Admin Instructor guide
- Cisco Press CCDA Study Guide
- Linux Network Admistrator's Guide
- Linux Network Administrators' Guide
- User Guide
- Wszystko dla pan Zola E
- Foster Alan Dean Zaginiona Dinotopia
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- protectorklub.xlx.pl
[ Pobierz całość w formacie PDF ]
.Standard events for all controlsThe most basic events are defined in the class TControl.All controls, whetherwindowed, graphical, or custom, inherit these events.The following are eventsavailable in all controls:OnClick OnDragDrop OnEndDrag OnMouseMoveOnDblClick OnDragOver OnMouseDown OnMouseUpThe standard events have corresponding protected virtual methods declared inTControl, with names that correspond to the event names.For example, OnClickevents call a method named Click, and OnEndDrag events call a method namedDoEndDrag.42-4 Dev el oper s Gui deI mp l e me n t i n g t h e s t a n d a r d e v e n t sStandard events for standard controlsIn addition to the events common to all controls, standard windowed controls (thosethat descend from TWinControl) have the following events:OnEnter OnKeyDown OnKeyPressOnKeyUp OnExitLike the standard events in TControl, the windowed-control events havecorresponding methods.Making events visibleThe declarations of the standard events in TControl and TWinControl are protected, asare the methods that correspond to them.If you are inheriting from one of theseabstract classes and want to make their events accessible at runtime or design time,you need to redeclare the events as either public or published.Redeclaring a property without specifying its implementation keeps the sameimplementation methods, but changes the protection level.You can, therefore, takean event that is defined in TControl but not made visible, and surface it by declaring itas public or published.For example, to create a component that surfaces the OnClick event at design time,you would add the following to the component s class declaration.class PACKAGE TMyControl : public TCustomControl{’__published:__property OnClick; // Makes OnClick available in the Object Inspector};Changing the standard event handlingIf you want to change the way your component responds to a certain kind of event,you might be tempted to write some code and assign it to the event.As anapplication developer, that is exactly what you would do.But when you are creatinga component, you must keep the event available for developers who use thecomponent.This is the reason for the protected implementation methods associated with each ofthe standard events.By overriding the implementation method, you can modify theinternal event handling; and by calling the inherited method you can maintain thestandard handling, including the event for the application developer s code.The order in which you call the methods is significant.As a rule, call the inheritedmethod first, allowing the application developer s event-handler to execute beforeyour customizations (and in some cases, to keep the customizations from executing).There may be times when you want to execute your code before calling the inheritedmethod, however.For example, if the inherited code is somehow dependent on theCr eat i ng ev ent s 42-5De f i n i n g y o u r o wn e v e n t sstatus of the component and your code changes that status, you should make thechanges and then allow the user s code to respond to them.Suppose you are writing a component and you want to modify the way it respondsto mouse clicks.Instead of assigning a handler to the OnClick event as a applicationdeveloper would, you override the protected method Click:void __fastcall TMyControl::Click(){TWinControl::Click(); // perform standard handling, including calling handler// your customizations go here}Defining your own eventsDefining entirely new events is relatively unusual.There are times, however, when acomponent introduces behavior that is entirely different from that of any othercomponent, so you will need to define an event for it.There are the issues you will need to consider when defining an event:" Triggering the event" Defining the handler type" Declaring the event" Calling the eventTriggering the eventYou need to know what triggers the event.For some events, the answer is obvious.For example, a mouse-down event occurs when the user presses the left button onthe mouse and Windows sends a WM_LBUTTONDOWN message to the application.Upon receiving that message, a component calls its MouseDown method, which inturn calls any code the user has attached to the OnMouseDown event.But some events are less clearly tied to specific external occurrences.For example, ascroll bar has an OnChange event, which is triggered by several kinds of occurrence,including keystrokes, mouse clicks, and changes in other controls.When definingyour events, you must ensure that all the appropriate occurrences call the properevents.Two kinds of eventsThere are two kinds of occurrence you might need to provide events for: userinteractions and state changes.User-interaction events are nearly always triggered bya message from Windows, indicating that the user did something your componentmay need to respond to.State-change events may also be related to messages fromWindows (focus changes or enabling, for example), but they can also occur throughchanges in properties or other code.You have total control over the triggering of the42-6 Dev el oper s Gui deDe f i n i n g y o u r o wn e v e n t sevents you define.Define the events with care so that developers are able tounderstand and use them.Defining the handler typeOnce you determine when the event occurs, you must define how you want the eventhandled.This means determining the type of the event handler.In most cases,handlers for events you define yourself are either simple notifications orevent-specific types.It is also possible to get information back from the handler.Simple notificationsA notification event is one that only tells you that the particular event happened,with no specific information about when or where.Notifications use the typeTNotifyEvent, which carries only one parameter, the sender of the event.All a handlerfor a notification knows about the event is what kind of event it was, and whatcomponent the event happened to.For example, click events are notifications.Whenyou write a handler for a click event, all you know is that a click occurred and whichcomponent was clicked.Notification is a one-way process.There is no mechanism to provide feedback orprevent further handling of a notification.Event-specific handlersIn some cases, it is not enough to know which event happened and what componentit happened to.For example, if the event is a key-press event, it is likely that thehandler will want to know which key the user pressed.In these cases, you needhandler types that include parameters for additional information.If your event was generated in response to a message, it is likely that the parametersyou pass to the event handler come directly from the message parameters.Returning information from the handlerBecause all event handlers return void only, the only way to pass information backfrom a handler is through a parameter passed by reference.Your components can usesuch information to determine how or whether to process an event after the user shandler executes.For example, all the key events (OnKeyDown, OnKeyUp, and OnKeyPress) pass byreference the value of the key pressed in a parameter named Key
[ Pobierz całość w formacie PDF ]