[ Pobierz całość w formacie PDF ]
.Objects is aproperty of type TObject so that it can hold any kind of object.When you retrieveobjects from the array, you need to typecast them back to the actual type of the items.7-16 Devel oper s Gui deAd d i n g g r a p h i c s t o c o n t r o l sDrawing owner-draw itemsWhen an application needs to draw or redraw an owner-draw control, the operatingsystem generates draw-item events for each visible item in the control.Depending onthe control, the item may also receive draw events for the item as a part of the item.To draw each item in an owner-draw control, attach an event handler to the draw-item event for that control.The names of events for owner drawing typically start with one of the following:" OnDraw, such as OnDrawItem or OnDrawCell" OnCustomDraw, such as OnCustomDrawItem" OnAdvancedCustomDraw, such as OnAdvancedCustomDrawItemThe draw-item event contains parameters identifying the item to draw, the rectanglein which to draw, and usually some information about the state of the item (such aswhether the item has focus).The application handles each event by rendering theappropriate item in the given rectangle.For example, the following code shows how to draw items in a list box that hasbitmaps associated with each string.It attaches this handler to the OnDrawItem eventfor the list box:procedure TFMForm.DriveTabSetDrawTab(Sender: TObject; TabCanvas: TCanvas;R: TRect; Index: Integer; Selected: Boolean);varBitmap: TBitmap;beginBitmap := TBitmap(DriveTabSet.Tabs.Objects[Index]);with TabCanvas dobeginDraw(R.Left, R.Top + 4, Bitmap); { draw bitmap }TextOut(R.Left + 2 + Bitmap.Width, { position text }R.Top + 2, DriveTabSet.Tabs[Index]); { and draw it to the right of thebitmap }end;end;Wor k i ng wi t h cont r ol s 7-177-18 Devel oper s Gui deCh a p t e r8Chapter8Building applications, components,and librariesThis chapter provides an overview of how to create applications, components, andlibraries.Creating applicationsThe most common types of applications you can design and build are:" GUI applications" Console applications" Service applications" Packages and DLLsGUI applications generally have an easy-to-use interface.Console applications runfrom a console window.Service applications are run as Windows services.Thesetypes of applications compile as executables with start-up code.You can create other types of projects such as packages and DLLs that result increating packages or dynamically linkable libraries.These applications produceexecutable code without start-up code.Refer to Creating packages and DLLs onpage 8-11.Bui l di ng appl i c at i ons , c omponent s, and l i br ar i es 8-1Cr e a t i n g a p p l i c a t i o n sGUI applicationsA graphical user interface (GUI) application is one that is designed using graphicalfeatures such as windows, menus, dialog boxes, and features that make theapplication easy to use.When you compile a GUI application, an executable file withstart-up code is created.The executable usually provides the basic functionality ofyour program, and simple programs often consist of only an executable file.You canextend the application by calling DLLs, packages, and other support files from theexecutable.The IDE offers two application UI models:" Single document interface (SDI)" Multiple document interface (MDI)In addition to the implementation model of your applications, the design-timebehavior of your project and the runtime behavior of your application can bemanipulated by setting project options in the IDE.User interface modelsAny form can be implemented as a single document interface (SDI) or multipledocument interface (MDI) form.An SDI application normally contains a singledocument view.In an MDI application, more than one document or child windowcan be opened within a single parent window.This is common in applications suchas spreadsheets or word processors.For more information on developing the UI for an application, see Chapter 9, Developing the application user interface.SDI applicationsTo create a new SDI application:1 Choose File|New|Other to bring up the New Items dialog.2 Click on the Projects page and double-click SDI Application.3 Click OK
[ Pobierz całość w formacie PDF ]