[ Pobierz całość w formacie PDF ]
.One of the main groups of classes in this branch is the Exception class.This classprovides a large set of built-in exception classes for automatically handlingdivide-by-zero errors, file I/O errors, invalid typecasts, and many other exceptionconditions.Another type of group in the TObject branch are classes that are encapsulated datastructures, such as:" TBits, a class that stores an  array of Boolean values" TList, a linked list class" TStack, a class that maintains a last-in first-out array of pointers" TQueue, a class that maintains a first-in first-out array of pointersYou can also find wrappers around external objects like TPrinter, which encapsulatesthe Windows printer interface, and TRegistry, a low-level wrapper for the systemregistry and functions that operate on the registry.TStream is good example of another type of class in this branch.TStream is the baseclass type for stream objects that can read from or write to various kinds of storagemedia, such as disk files, dynamic memory, and so on.So you can see, this branch includes many different types of classes that are veryuseful to you as a developer.2-4 Dev el oper  s Gui de Ob j e c t s , c o mp o n e n t s , a n d c o n t r o l s i n t h e VCLThe TPersistent branchDirectly below TObject in the VCL hierarchy is TPersistent.TPersistent adds two veryimportant methods to all classes based on it SaveToStream and LoadFromStream.These methods supply persistence to objects.For example, when the form designer needs to create a DFM file (a file used to storeinformation about the components on the form), it loops through its componentsarray and calls SaveToStream for all the components on the form.Each component knows how to write its changed properties out to a stream (in this case, a text file).Conversely, when the form designer needs to load the properties for componentsfrom the DFM file, it loops through the components array and calls LoadFromStreamfor each component.Thus, any class derived from TPersistent has the ability to saveits state information and restore it on demand.The types of classes in this branch include:" TGraphicsObject, an abstract base class for objects which encapsulate Windowsgraphics objects: TBrush, TFont, and TPen." TGraphic, an abstract base class type for objects such as icons, bitmaps, andmetafiles that can store and display visual images: TBitmap, TIcon, and TMetaFile." TStrings, a base class for objects that represent a list of strings." TClipboard, a wrapper for the Windows clipboard, which contains text or graphicsthat have been cut or copied from an application." TCollection, TOwnedCollection, and TCollectionItem, maintained indexed collectionsof specially defined items.The TComponent branchTComponent is the common ancestor of all VCL components.Components are objectsthat you can manipulate on forms at design time.Despite its name, the VCL consistsmostly of nonvisual objects.VCL components are persistent objects that have the following capabilities:" The ability to appear on the Component palette and be changed in the formdesigner." The ability to own and manage other components." Enhanced streaming and filing capabilities." The ability to be converted into an ActiveX control or other COM object bywizards on the ActiveX page of the New Objects dialog.TComponent acts as the standard  bus that all components plug into.There areseveral methods in TComponent that dictate how components act during design time.This is also where the Name and Owner properties are introduced.Every componentderived from TComponent has a Name and an Owner property.The owner isresponsible for deleting the component.Pr ogr ammi ng wi t h C++Bui l der 2-5 Ob j e c t s , c o mp o n e n t s , a n d c o n t r o l s i n t h e VCLComponents that do not need a visual interface are derived directly fromTComponent.The types of classes that can be found in this branch include:" TMainMenu, a class that provides a menu bar and its accompanying drop-downmenus for a form." TTimer, a class that includes the Windows API timer functions." TOpenDialog, TSaveDialog, TFontDialog, TFindDialog, TColorDialog, and so on, thecommon windows dialog boxes." TActionList, a class that maintains a list of actions used with components andcontrols, such as menu items and buttons." TScreen, a class that keeps track of what forms and data modules have beeninstantiated by the application, the active form, and the active control within thatform, the size and resolution of the screen, and the cursors and fonts available forthe application to use.The TControl branchAll controls are visual objects, meaning the user can see them and manipulate themat runtime.All controls have properties, methods, and events in common that arespecific to the visual aspect of controls, such as the position of the control, the cursoror hint associated with the control s window, methods to paint or move the control,and events to respond to mouse actions.Whereas TComponent defines behavior for all components, TControl defines behaviorfor all visual controls.This includes drawing routines, standard Windows events,and containership.One group of classes in this branch is called TGraphicControls.TGraphicControls arecontrols that must draw themselves and can never receive focus.The types ofcontrols that can be found in this group include:" TImage, a control that displays graphical images." TLabel, a control that displays text on a form." TBevel, a control that represents a beveled outline." TPaintBox, a control that provides a canvas that applications can use for drawingor rendering an image.Notice that these include the common paint routines (Paint, RePaint, Invalidate, etc.)but C++Builder doesn t have to allocate a window handle for them because theynever need to receive focus.2-6 Dev el oper  s Gui de Ob j e c t s , c o mp o n e n t s , a n d c o n t r o l s i n t h e VCLThe TWinControl branchTWinControl is the base class for all windowed controls.The following are features ofwindowed controls:" Windowed controls are controls that can receive focus while the application isrunning." Other controls may display data, but the user can use the keyboard to interact witha control only if the control is a windowed control." Windowed controls can contain other controls." A control that contains other controls is a parent.Only a windowed control can bea parent of one or more other child controls." Windowed controls have a window handle.TWinControls are like TControls except they can receive focus.This means that thereare many more standard events that apply to them and that Windows must allocate awindow handle for them.This branch includes both controls that are drawn automatically by Windows(including TEdit, TListBox, TComboBox, TPageControl, and so on) and custom controlsthat C++Builder must draw (including TDBNavigator, TMediaPlayer, TGauge, and soon).However, you never have to worry about any of the implementation details ofhow the controls render themselves or how they respond to events C++Buildercompletely encapsulates this behavior for you.The following sections provide an overview of controls.Refer to Chapter 5, Working with controls for more information on using controls [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • higrostat.htw.pl
  •