Home

Introduction to Applications

 

Windows Fundamentals

 

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.

Object Pascal in a VCL Application

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.

Applications Fundamentals

 

Introduction to VCL Objects

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:

VCL Inheritance

  1. The ability to create an object, thereby allocating the necessary memory resources needed during the lifetime of the object
  2. The ability to maintain an object. That is, to be able to locate it, both by the application and the operating system. This also makes it possible for other objects of the same application or for the operating system to be aware of the presence of the object
  3. The ability to destroy an object when it is not needed anymore, thereby freeing the resources the object was using and make these resources available to the operating system and consequently to other objects and application

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.

Introduction to Object Persistence

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 Inheritance

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 ":=".

Introduction to Components

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:

VCL Inheritance

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.

Introduction to Controls

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:

TControl Inheritance

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.

Introduction to Windows Controls

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:

TWinControl

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.

Introduction to Application Initialization

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:

typedef struct _WNDCLASS {
     UINT       style;
     WNDPROC    lpfnWndProc;
     int        cbClsExtra;
     int        cbWndExtra;
     HINSTANCE  hInstance;
     HICON      hIcon;
     HCURSOR    hCursor;
     HBRUSH     hbrBackground;
     LPCTSTR    lpszMenuName;
     LPCTSTR    lpszClassName;
 } WNDCLASS, *PWNDCLASS;
typedef struct _WNDCLASSEX {
	UINT cbSize;
	UINT style;
 	WNDPROC lpfnWndProc;
 	int cbClsExtra;
 	int cbWndExtra;
 	HINSTANCE hInstance;
 	HICON hIcon;
 	HCURSOR hCursor;
 	HBRUSH hbrBackground;
 	LPCTSTR lpszMenuName;
 	LPCTSTR lpszClassName;
 	HICON hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;

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:

TApplication Inheritance

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:

procedure Initialize

This creates an empty application without much to do.

 

Application's Instance

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.

When you create a VCL application, a variable of type TApplication is declared and the instance of the application is globally made available to anything that needs it. The instance of the application is called HInstance.

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.

Introduction to Application's Screen

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:

TScreen Inheritance

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.

Creating and Opening a VCL Forms Application

 

Creating a Project

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:

  • On the Welcome Page, position the mouse on Projects and click New Project
  • At any time, on the main menu, click File -> New -> VCL Forms Application - Delphi
  • To use the New Items dialog box:
    • On the Welcome Page, under Recent Projects, click the New Project link
    • On the main menu, click File -> New -> Other
    • On the Standard toolbar, click the New Items button New Items
       
      Any of these actions would open the New Items dialog box. In the left section, click Delphi Projects. In the right list, double-click VCL Forms Application
       
      New Items
  • If no project is currently being developed or when no form is showing, you can use the Tool Palette. Click Delphi Projects to expand it. Then double-click the VCL Forms Application icon VCL Forms Application
     
    VCL Forms Application

Any of these actions would create a new project and display a starting form.

Opening a Project

To open a project:

  • On the main menu, click File -> Open Project...
  • On the Standard toolbar, click the Open Project button Open Project
  • On the Welcome Page, position the mouse on Projects, and click Open Project
  • On the Welcome Page, click the Open Project... link
  • To open a project that was recently used:
    • On the main menu, click File -> Reopen, and click the name from the list
    • On the Welcome Page, under Recent Projects, click the name of the project
    • On the Welcome Page, under Recent Opened Projects, click the name of the project

Help

 

Introduction

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.

Getting General Help

To access the main Delphi help:

  • On the main menu of RAD Studio, you can click Help -> Delphi Help
  • On the task bar, you can click Start -> (All) Programs -> Embarcadero RAD Studio 2010 -> RAD Studio Documentation

Practical LearningPractical Learning: Starting Help

  1. On the main menu, click Help -> Delphi Help
  2. Click the Index tab
  3. In the Look For combo box, type AnsiStr
     
    Help
  4. Notice that the Help environment finds the closest matches
  5. In the list, click AnsiStrComp
  6. Notice the text on the right side of the window
  7. Once again in the Look For text box, type SQL and notice some sub-titles under it
  8. Click Executing commands
  9. Notice the options in the lower-right section of the window
     
    Help
  10. Notice that the main right section of the window displays the details of the item selected
  11. Close the Help window and return to Delphi

Help on a Word

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.

Practical LearningPractical Learning: Getting Contextual Help

  1. Double-click somewhere in the middle of the form
  2. Type TButtonn
  3. Click between B and u
  4. Press F1
     
    Topics
  5. On the left side, click the + button of TButton
  6. Click the + button of Properties
  7. Click Align Property
  8. Close the Help window 

MSDN Help

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:

  • On the main menu of RAD Studio, you can click Help -> Search
  • If the Help window is already opened, on its Standard toolbar, click Search

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.

Practical LearningPractical Learning: Accessing the MSDN Help

  1. On the main menu, click Help -> Search
  2. In the text box, type FileStream
  3. Click the Search button
     
    Help
  4. In the list of topics, double-click FileStream Class (System.IO)
     
    Help

Internet Help

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.

Practical LearningPractical Learning: Exploring Internet Help

  1. In the Help window, on the right side of URL, click the address to select it
  2. Type http://msdn.microsoft.com and press Enter
  3. Close the Help window
 
 
 
 

Previous Copyright © 2010 FunctionX, Inc. Next