Introduction to Applications
Introduction to the Win32 Library
A library is a set of published documents. It could consist of a piece of paper, a book, or a group of books used as a (written) reference for a specific purpose. The programs that are on a Microsoft Windows operating system follow a set of rules and suggestions defined in a library called Win32 (Windows 32-bits).
Win32 is a group of files, functions, objects, resources, data types, and constants that define how the Microsoft Windows family of operating systems function. As a reference, it allows individuals and companies to know what is necessary in order to create or develop applications for this specific platform.
Over all, it is not strictly necessary to know Win32 thoroughly to write programs; but it is highly recommended to know as much as possible about Win32 to be an effective Windows programmer.
As you may know already, you will use your knowledge of Pascal to develop Delphi applications. This includes the ability to create objects, declare variables, create classes, use your own classes, use or use classes created by other people, etc. Most of the classes you will use have already been created. Still, in some cases, you will have to create new classes.
To manage classes, you can use the Class Explorer. To get it, on the main menu, you can click View -> Delphi Class Explorer.
To make application development easier, that is, to provide Rapid Application Development (RAD), the Visual Component Library (VCL) is equipped with various classes. The most fundamental class is named TObject. This is the ancestor to all VCL classes you will use in an application. The TObject class is defined in the System.hpp header file. As the parent of all VCL classes, it gives some common functionalities to its children, including:
You will hardly, if ever, need to declare a variable of type TObject. Instead, if necessary, you can create a class that derives from TObject. The TObject class is equipped with many methods and no properties.
Persistence is the ability to write or to read a value. The value can be written to an object. The object can be physical such as a hard drive or a DVD drive, or it can be virtual such as a variable. In the same way, the value can be read from the same type of object. These two operations make it possible to share values, such as to assign one object to another. To provide this functionality to objects, the VCL provides a class named TPersistent. The TPersistent class is defined in the Classes.pas file.
The TPersistent class is derived from TObject:
TPersistent is the ancestor to all classes that use properties, so these properties can be written to or read from. The TPersistent class is equipped with a method named Assign. Its syntax is:
procedure Assign(Source: TPersistent); virtual;
This method makes it possible to assign an object to another object. You can either use this method or the assignment operator ":=".
A component is an object that is used in a graphical application. Examples of components are buttons, pictures, check boxes, mouse cursors, or lists. The most fundamental aspect of a component is that it must be created. The most fundamental object of a computer is the operating system. It gives life to the computer and the objects that would appear on it. Most of these objects are seen on the screen. In fact, as far as a user is concerned, an application is a series of objects that can be seen and used. Some objects can carry other objects, which means they act as parents. An object A that holds or carries another object B is referred to as its owner.
To support these various scenarios, the ability for a component to appear in an application and the ability for one component to own another component, the VCL provides a class named TComponent. The TComponent class is defined in the Classes.pas file.
The TComponent class is derived from TPersistent:
TComponent is the ancestor for objects that appear in an application. The TComponent class is equipped with many properties and methods.
As mentioned already, one of the characteristics of a component is that it can own other components. To give you access to the objects that a component owns, the TComponent class is equipped with a property named Components:
property Components: TComponent read GetComponent;
The TComponent.Components property is a collection where each element is an object on the component. One of the properties of the TComponent class is named ComponentCount:
property ComponentCount: Integer read GetComponentCount;
TComponent.ComponentCount is a read-only property that produces the number of objects that a component owns. On the other hand, to let you get a reference to the parent component of an object, the TComponent class is equipped with the Owner property:
property Owner: TComponent read FOwner;
To let you get the name of a component, the TComponent class is equipped with a property named Name:
property Name: TComponentName read FName write SetName;
This Name property is inherited by all other classes that inherit directly or indirectly from TComponent. Another valuable property of the TComponent class is named Tag:
property Tag: Integer read FTag write FTag;
The role of the TComponent.Tag is not defined by anything other than it is available. This means that you can use the Tag property anyway you want. The only thing you have to know is that it can be assigned an integer value that you can later use anyway you want.
In a computer application, a control is an object that appears, or has a physical presence, on the screen. To make this possible, a control presents some visual characteristics such as borders or colors. A control can also exhibit a behavior, such as the ability to move or change.
To support the concept of controls, the VCL provides a class named TControl. The TControl class is derived from TComponent:
The TControl class is defined in the Controls.pas file. The TControl class is equipped with many properties and methods that we cannot review at this time.
A Windows control is an object that can react to a user. For example, it can receive key strokes (from the keyboard) or can respond when a mouse acts on it. Examples of Windows controls are buttons, list views, check boxes, menus, radio buttons, dialog boxes, or scroll bars.
To support Windows controls, the VCL provides a class named TWinControl. The TWinControl class is derived from TControl:
The TWinControl class is defined in the Controls.pas file. The TWinControl class is equipped with many properties and methods that we cannot review at this time.
A computer application, also called an application, is a series of instructions that tell the computer what to do, when an how. These instructions are group in one entity named a project. In Microsoft Windows, to create an application, you use one of two structures named WNDCLASS and WNDCLASSEX. These two structures are defined respectively as follows:
For a Win32 application, you must declare a variable of one of these structures. Then you should provide, or at least control, the value of each of the member variables.
To support applications, or to simplify the creation of an application, the VCL provides a class named TApplication. The TApplication class is derived from the TComponent class:
The TApplication class is defined in the Forms.pas package. TApplication is used to create, or get access to, an application. It is the main central point of an application as a Windows entity.
To give you ample access to the application and to the screen, every GUI application you develop using the VCL declares a TApplication variable. This means that you will hardly, if ever, need to declare a variable of this class since it is already available to your application.
To create an application, the TApplication class provides the Initialize() method. Its syntax is simply:
This creates an empty application without much to do.
If you start an application such as Notepad, you are
said to have created an instance of the application. In the same way, when
you declare a variable of a class, an instance of the class is created and
made available to the project. In fact, when you create an application, you
must create an instance of that application so it can be made available to
the operating system. Once the instance exists, it can be accessed either by
any control of the same application or by the operating system.
After creating an application, you can create an object that the user will look at when interacting with the computer. Such an object is called a window. Most of the things you see on the screen or on an application are window objects. As various as they are, there are different techniques used to create them.
The screen is the monitor that allows a person to visually interact with the machine. The screen includes such information as the computer's desktop, its size, the display monitor, and other pieces of information related to a screen as an object or related to the objects of an application.
To give you information about the screen that is being used in your application, the VCL provides the TScreen class. The TScreen class is derived from TComponent:
As mentioned for the TApplication class, when you create a VCL project, a global TScreen variable is automatically declared so you will never need to explicitly create a TScreen object.
Rapid application programming (RAP) and rapid application development (RAD) consists of visually creating a computer program by adding objects to the projects and writing code only when necessary. This makes the development go fast and allows the programmer to regularly preview the result. Although you can manually create a fully functional application in Embarcadero RAD Studio, the goal of using it is to take advantage of its rich design interface and objects. For this reason, for the rest of our lessons, we will use RAD as much as possible.
There are many ways you can start a visual application in Embarcadero RAD Studio:
Any of these actions would create a new project and display a starting form.
To open a project:
There are two main sources of help available for Delphi. The first source of help is provided with the programming environment. This help is electronic and it is divided in two. Everything considered, this is the closest and the highest documentation that the compiler provides.
To access the main Delphi help:
You can get help on a particular item on the screen. To get this type of help, in the Code Editor, click inside a word and press F1. The Help window would come up and would display information related to that word.
Because the new RAD Studio shares some features with the Microsoft Developer Network (MSDN), you will need close attention to the MSDN documentation. Fortunately, the RAD Studio ships with, and installs the MSDN documentation. To access it:
Any of these actions would open a Search tab and display a text box. In the Search text box, type the word or expression you want, and click Search or press Enter.
Another place you can find information is on the Internet. Fortunately, most of that help is free. On search engine’s web site, you can perform a search on the expression Delphi (or C++ Builder) and see what you get.
Because a great part of the Delphi applications implement the Win32 API, it is very important that you have access to the Microsoft Developer Network documentation. As mentioned above, this help is available from the RAD studio. It is also available free from http://msdn.microsoft.com.
|Previous||Copyright © 2010-2015, FunctionX||Next|