Вы находитесь на странице: 1из 2

Chapter 6 The class libraries

by Michael Van Canneyt

Developing programs in Lazarus uses Object Oriented Programming (OOP). Whenever you design an application's GUI, or its business objects, or some other interaction with the Operating System (OS), you will always be using classes or objects. The entire gamut of classes available for you to use is organized in three distinct groups or layers: RTL The Free Pascal Run Time Library. This contains all the functions which you need for interaction with the OS. It contains both platform-specific and platformindependent units. Generally, the routines you find in the RTL units are not object oriented, but procedural. FCL The Free Pascal Free Component Library. This is a set of all-purpose crossplatform classes and components: components for image handling, process management, database access, web programming. In contrast to Delphi's VCL, the classes in Lazarus are strictly divided between a set of non-visual components, and a set of visual classes. The FCL contains only non-visual classes. LCL The Lazarus Component Library. This is the GUI layer of Lazarus which contains all Lazarus' visual code. The components in this layer abstract the underlying widget set. Consequently the same set of components can be used on all platforms, and it is the aim of the Lazarus team to make sure they work identically on all supported platforms.

The first two layers are part of Free Pascal, the compiler underlying Lazarus. Classes and routines in those layers can be used without Lazarus, by using the command-line compiler or another Free Pascal IDE (for instance MSEide, or fpGUI). The third layer, the LCL, is specific to Lazarus and how it defines GUI programming. One of Lazarus' goals is to encapsulate all supported widget sets in a set of components (the LCL) in such a way that another widget set can be used simply by recompiling the program using a different set of widget set units.

328

Lazarus - the complete guide

Chapter 6 The class . libraries

The following widget sets are supported: The Win32/win64 API. The Windows CE and Windows Mobile API, which is a reduced form of the Win32/win64 API. The platform-independent QT 4 widget set. It can be used on Windows, Linux/Unix, MacOS X and is supported well by Lazarus. The older GTK1 widget set. Until version 0.9.26 this was the default widget set in Lazarus on Linux/Unix, and hence is supported well. The newer GTK2 widget set. As of version 0.9.28 this is the default widget set in Lazarus on Linux/Unix, and hence is also well supported. Carbon on MacOS X. Free Pascal can access the Cocoa layer of MacOS X and the iPhone. The LCL currently does not support this widget set, so Cocoa programs must be written manually. fpGUI is an alternate widget set for Free Pascal. An LCL layer that builds on top of fpGUI is planned. Lazarus supports the Win32/Win64 and GTK1/GTK2 and Qt layers best of all (currently at the beta-stage). The other widget sets are alpha-stage components. The division between RTL, FCL and LCL, as well as the distinction between the various widget sets is largely academic and of little practical importance for the end-user application developer. The distinction between visual classes and non-visual components is more relevant. The visual classes or components are actual GUI elements: forms, buttons, checkboxes, edit components, menus anything that the user sees is a visual class. In Lazarus, all visual classes descend from TControl (defined in the LCL), and they are discussed below. Most of the components found on the Lazarus IDE's Component Palette are visual components. By contrast, the non-visual classes or components are classes that are not visible to the application user. They fall into one of two categories: components or non-components. The components are classes that can be dropped from the component palette onto a Lazarus form. They are then represented by a small icon on the form, so they can be selected by the programmer and subsequently manipulated through the IDE's Object Inspector. The non-component classes are classes that the programmer constructs manually in code to perform a required task. Since all visual controls descend from TControl, which is the base class defined in the LCL, all RTL and FCL classes are by definition non-visual. Nevertheless, there are a lot of component classes in the FCL which can be dropped on a Lazarus form. The database components are a good example of non-visual components defined in the FCL. Visual components also fall into one of two categories: 'normal' components, and their DB-aware counterparts, which are descendants of normal components, enhanced with the ability to connect to the data in a database.
Lazarus - the complete guide

329

Вам также может понравиться