Last Updated:

CLX Project

What is CLX Project?

Creating a cross-platform application in Delphi requires absolutely standard actions. It is enough to create a new project by selecting the CLX Application item in the Repository.

At first glance, the new project is no different from the usual one, but this is not so. And the development environment has also undergone some changes. The Component Palette now shows components from the CLX library, the same one that Kylix uses. And the few changes in the composition of the project are also associated with the need to combine with Kylix.

A CLX project differs from a regular clx project in that it contains information about a form. If in a normal project a form file has a .dfm extension, then in a CLX project it is a file with an .xfm extension that is equally understandable for Delphi and Kylix, so both files are ordinary text files and information about the form is represented in them in text form. You see much the same thing when you view the form in a text view in the Delphi Editor window (view as Text command from the form's pop-up menu).

Note that the form and the CLX module are linked using the {$R *.xfm} directive.

In addition, delphi and Kylix projects have different extensions for the project options file (in Delphi - dof, in Kylix - kof). However, this is not a fundamental problem and in the absence of such a file, the development environment will create a new one with default settings. That way, you can always think of at least a few ways to transfer the text contents of your project's settings file.

Now let's look at the source code of the project generated by Delphi – this will give us some interesting observations. In terms of syntax and basic elements, the source code does not differ from the standard code. The project file contains a list of modules and a begin. end. The module file is also common, except for the list of modules used in the uses section.

Above, we talked about the CLX component library and its role in cross-platform development. And modules with unusual names QControis, QForms, etc. just contain the base classes of the CLX library.

Otherwise, the CLX project is similar to a standard Delphi project and can use all the tools of the development environment and visual programming techniques.

To confirm this, with a few changes to the VCL project, we can easily convert the VCL project to CLX and vice versa. To do this, you will need any text editor. And of course, the project should not contain components that are not part of the CLX library.

  1. In the project file, in the uses section, change the reference to the Forms module to QForms.
  2. In the module files, replace references to VCL modules with CLX modules. For example, the uses section might look like this:
uses SysUtils, Types, Classes, QGraphics, QControls, QForms;
  1. In the module files, replace the {$R *.dfm} directive with {$R *.xfm}.
  2. In form files, replace the .dfm extension with .xfm.

After you save your changes and open the project in the development environment, you will verify that Delphi has mistaken it for a CLX project, modified the Component Palette accordingly, and is ready to compile it.

As for the code of a cross-platform application for Linux, the basic principles of its creation are discussed later in this chapter.

If necessary, the developer can add new templates to the project using the Repository. However, only templates that can be used in a CLX project (such as a form, module, or data module) are available in the Repository. There are no templates that cannot be used on Linux or that are not supported by the CLX library (for example, a single-document application template or Quick Report printing form templates).

Object concept of cross-platform programming

 

Programming in Delphi involves the use of certain classes, whether they are forms, non-visual components or lists. The concept of cross-platform programming within a single development environment refers to the presence of a common core that ensures the functioning of an operating system-dependent software add-in. In Delphi, this core is the RunTime Library (RTL), which is used to create the VCL and CLX component libraries.

Accordingly, changes have been made to the source code of the Delphi base classes to enable cross-platform development. The common core of the VCL and CLX content libraries is the hierarchy of TObject – TFersistent – TComponent classes, which are part of RTL. This allows the development environment to easily integrate cross-platform projects and work with standard Windows projects.

The divergences between the two branches begin with the TControl class, which provides functionality to all visual components. From this class onwards, content center libraries have their own source code. Many CLX modules have names similar to VCL modules, but with the addition of the first letter Q, such as QControls.pas.

In the VCL library, the TControl and Twincontrol classes are the ancestors of all components that must be able to display themselves on the screen using the graphical tools of the operating system. In the CLX library, the TControl and TWidgetControl classes perform a similar task. They ensure that child components work as widget display objects.

Most of the properties and methods of the Twincontrol and TWidgetControl classes are the same. However, there are differences caused by the peculiarities of the graphical interfaces of Windows and Linux operating systems.

For more information about the functionality of these VCL and RTL classes, see Chapter 2.

To ensure the functionality of cross-platform CLX classes, the Qt dynamic library is used. To use its methods in CLX classes, Delphi has a Qt.pas header file. When you create a CLX object by the create constructor in source code or by porting a component to a form, a special widget object is automatically created. The widget is associated with a CLX object, enables the CLX object to interact with the operating system, and is destroyed with it.

However, widget can also be created directly. This situation can arise, for example, when creating your own components. To do this, use the function QWidget_Create the Qt dynamic library. In this case, the widget is not tied to the CLX object and, accordingly, is not destroyed with it.

CLX Component Library

 

By far, the CLX component library is poorer than VCL. Nevertheless, its components allow you to create full-fledged applications. In general, the composition of CLX components resembles the Component Palette of earlier versions of Delphi. The CLX library is loaded into the Component Palette when you open an existing CLX project or create a new one.

All CLX components that have VCL counterparts, and most of them, have the same names as the VCL components. Because when you transfer components from the Component Palette to a form, the corresponding modules are automatically connected to the project, there are no problems with the double name.

The source modules of the CLX library are contained in the \Delphi7\Source \C1x folder.

The first three pages of the Component Palette (StandardAdditionalCommon Controls), as well as the Dialogs page, contain visual and non-visual components for designing the application's user interface.

Note
Because of some differences in the Windows and Linux user interface standards, some of the visual components of the CLX have additional features that are unusual for Windows. Differences in standard properties and methods are described below
.

Most of the components on these pages are familiar to developers (although some of them migrated from other VCL pages, such as TTimer and TSpinEdit). However, there are some novelties. These are the TLCDNumberTTextviewer, and TTextBrowser components. Their brief annotation is presented in Table. 4.1.

Table 4.1. Unique visual components of CLX.

ComponentComponent Palettes pageDescription
TLCDNumberAdditionalThe component displays a collection of characters (letters and numbers) that can be represented in digital display mode. Accordingly, not all letters can be shown in this component. for example the letters j q z and so on the character string is contained in the value property
TTextviewerCommon ControlsThe component is analogous to the VCL TRichEdit component. Designed to edit texts
TTextBrowserCommon ControlsThe component develops the capabilities of the TTextviewer component by providing hypertext markup functionality

Additional opportunities for creating cross-platform database applications are provided by components on the pages Data AccessDataControIsDBExpressInterBase. Of course, the data access mechanisms used by such applications are highly dependent on the operating system. Therefore, the choice of ways to access data is relatively small.

Also, the CLX library contains a fairly large number of components that allow you to create cross-platform applications for the Internet. These are the usual traditional components (Internet Pages, InternetExpressWebServices) and new ones from the Internet Direct (Indy) set.

Similarities and differences between the visual components of CLX and VCL

Most of the properties and methods of the VCL and CLX components are identical. And the existing differences are caused by the need to use special objects - widget and the peculiarities of the presentation of visual elements in Linux.

The CLX base classes, TControl and Twidgetcontrol, access the Qt dynamic library through the Qt.pas header file to provide rendering.

Thus, the developer is spared from the need to work with the Graphical Interface of Linux at a low level.

For a CLX component, there is a property:

property Handle: QWidgetH;

This is a pointer to the associated widget object and allows you to call its methods directly.

If no widget instance is created, the method:

procedure CreateHandle; virtual;

Not only does it create and initialize a widget, but it also sets a Handle pointer, creates interceptors (see below), and sets default settings for this visual component. Optionally, in the child classes, the CreateHandle method overlaps and adds new functionality to it.

The destruction of the created widget is carried out by the method:

procedure DestroyHandle;

Which destroys all child widgets and interceptors, and resets the Handle and Hooks properties.

If necessary, you can use the following method to easily create and initialize the widget:

procedure CreateWidget; virtual;

Which will do this by calling an external function Qwidget_Create, and a method:

procedure InitWidget; virtual;

Which defines the visual parameters of the widget.

Also in clX classes, a pointer to the parent widget is available by using the property:

property ParentWidget: QWidgetH;

If this property is not defined, you can use the following property:

property ChildHandle: QWidgetH;

A parent class, for example, like this:

if Not Assigned(ParentWidget) then if Assigned(Parent) then
Result: = Parent.ChildHandle;

The CLX classes implement event handling differently. In Linux, all events are divided into two types – system events and widget events. System events are handled by the procedure, which is analogous to the wndProc procedure for VCL components.

Events generated by the widget are intercepted and processed by special objects that interact with the widget object. They are then passed to the associated CLX object, which calls the necessary event handlers.

Interceptor objects are created when the method is called:

procedure HookEvents; virtual;

And directly to create interceptors, the library function Qwidget_hook_create is used. The HookEvents method is called automatically when the widget is created.

The interceptor object can be accessed using the following property:

property Hooks: QWidget_hookH;

Which is declared in the protected section and can only be used when creating new components.

ClX classes have a very interesting and important property:

property Style: TWidgetStyle;

Which allows you to control the appearance and rendering process of the component.

Property:

type TDefaultStyle = (dsWindows, dsMotif, dsMotifPlus, dsCDE, dsQtSGI, dsPlatinum, dsSystemDefault);
 property DefaultStyle: TDefaultStyle;

The TWidgetStyle class defines the style of a visual component that specifies its default appearance. Naturally, the operating system must support the chosen style.

In addition, the Twidgetstyle class defines some of the most common parameters of visual components and has a huge number of event handlers that are called when all possible components and screen elements are rendered.

Thus, the style property is an excellent tool for creating your own components with non-standard functionality.

For use on Linux, the contextual assistance system for CLX components has been upgraded. Now, article hints for a visual component can be invoked in two ways.

Traditionally, by defining a unique article number in a property:

property HelpContext: THelpContext;

And additionally, by defining the hint keyword in the property:

property HelpKeyword: String;

The way to call help is determined by the property:

type THelpType = (htKeyword, htContext);
property HelpType: THelpType;

Note
Contextual ToolTip properties are new in Delphi 7 and are available for CLX and VCL components
.

In addition, individual CLX components have additional properties and methods that define their additional functionality in Linux.

At the same time, some of the component properties familiar to Windows programming are missing from CLX components. These are the framing properties of the component (BevelEdgesBevellnnerBevelKindBevelOuter); the possibility of bidirectional printing of texts (BioiMode property); Properties for backward compatibility with Windows 3.x (Ctl3D and ParentCtl3D) the join mechanism and Drag-and-Drop properties, although the Drag-and-Drop mechanism itself remains (DockSiteDragKindDragCursor properties).