RAD Studio
ContentsIndex
PreviousUpNext
VCL Procedures

This section provides how-to information on developing VCL for Win32 applications.

Name 
Description 
This "Hello World" console application demonstrates the essential steps for creating a Windows application in Delphi or C++. The application uses Windows, a console window, an event, and will display a dialog in response to a user action. 
The following procedure illustrates the essential steps for building a Windows application. 
Menus provide an easy way for your users to execute logically grouped commands. You can add or delete menu items, or drag them to rearrange them during designtime. In addition to TMainMenu and TPopupMenu components, the Tool Palette also contains TActionMainMenuBar, TActionManager, and TActionToolBar
Creating a form with tables and graphs of multidimensional data consists of the following major steps:
  1. Create a VCL form.
  2. Add a decision query and dataset.
  3. Add a decision cube.
  4. Add a decision source.
  5. Optionally add a decision pivot.
  6. Add one or more decision grids and graphs.
  7. Set the active property of the decision query (or alternate dataset component) to True.
 
Each of the procedures listed below builds a VCL Form application that uses graphics. Build one or more of the examples and then add other graphics features to these basic VCL Form applications.
  1. Draw straight lines.
  2. Draw rectangles and ellipses.
  3. Draw a polygon.
  4. Display a bitmap image.
  5. Place a bitmap in a combo box.
 
The VCL Forms MDI application wizard automatically creates a project that includes the basic files for an MDI application. In addition to the Main source file, the wizard creates unit files for child and about box windows, along with the supporting forms files and resources. 
 
 
You can use the New VCL Component wizard to create a new VCL component for your application. The wizard detects the personality of the product you are using and creates the appropriate type of component. 
The following procedure describes how to build an ADO database application.
Building a VCL ADO application consists of the following major steps:
  1. Set up the database connection.
  2. Set up the dataset.
  3. Set up the data provider, client dataset, and data source.
  4. Connect a DataGrid to the connection components.
  5. Run the application.
 
The following procedure illustrates the essential steps to building a VCL Forms application using RAD Studio. 
Using RAD Studio, the following procedure illustrates how to create actions using the ActionList tool. It sets up a simple application and describes how to create a file menu item with a file open action.
Building the VCL application with ActionList actions consists of the following major steps:
  1. Create a main window and add tools for creating a main menu and a File open action.
  2. Add the File category to the main menu.
  3. Add the File open action to the File category.
  4. Build and run the application.
 
This procedure demonstrates how to construct a simple “Hello world” VCL Forms application using either Delphi or C++. Though simple, the Windows Forms "Hello world" application demonstrates the essential steps for creating a VCL Forms application. The application uses a VCL Form, a control, an event, and displays a dialog in response to a user action.
Creating the "Hello world" application consists of the following steps:
  1. Create a VCL Form with a button control.
  2. Write the code to display "Hello world" when the button is clicked.
  3. Run the application.
 
Using RAD Studio, the following procedure illustrates how to create actions using ActionManager. It sets up a simple user interface with a text area, as would be appropriate for a text editing application, and describes how to create a file menu item with a file open action.
Building the VCL application with ActionManager actions consists of the following major steps:
  1. Create a main window.
  2. Add a File open action to the ActionManager.
  3. Create the main menu.
  4. Add the action to the menu.
  5. Build and run the application.
 
The following procedure describes how to build a dbExpress database application.
Building a VCL Forms dbExpress application consists of the following major steps:
  1. Set up the database connection.
  2. Set up the unidirectional dataset.
  3. Set up the data provider, client dataset, and data source.
  4. Connect a DataGrid to the connection components.
  5. Run the application.
 
This example creates a VCL Forms application that uses an XMLDocument component to display contents in an XML file. 
Creating this VCL application consists of the following steps:
  1. Create a project directory containing a text file to copy.
  2. Create a VCL Form with a button control.
  3. Write the code to read the string and write it to a file.
  4. Run the application.
 
Copying a string list can have the effect of appending to or overwriting an existing string list. This VCL application appends to a string list. With a simple change, it can overwrite a string list. Creating this VCL application consists of the following steps:
  1. Create a VCL Form with TButtons, TComboBox, and TMemo controls.
  2. Write the code to create a string list to the Button1 OnClick handler.
  3. Write the code to copy the string list to the Button2 OnClick handler.
  4. Run the application.
 
Creating this VCL application consists of the following steps:
  1. Create a VCL Form with TButton and TComboBox controls.
  2. Write the code to create strings to the TButton OnClick handler.
  3. Run the application.
 
A safe way to create a unique instance of a modal VCL form is to use a local variable in an event handler as a reference to a new instance. If you use a local variable, it doesn't matter whether the form is auto-created or not. The code in the event handler makes no reference to the global form variable. Using RAD Studio, the following procedure creates a modal form instance dynamically. It (optionally) removes the second form's invocation at startup.
Building this VCL application consists of the following steps:
  1. Create the project directory.
  2. Create two forms for the project.... more 
Creating this VCL application consists of the following steps:
  1. Create a VCL Form with Buttons and ListBox controls.
  2. Write the code to add strings to a list.
  3. Write the code to delete a string from the list.
  4. Run the application.
 
Using RAD Studio, the following procedure creates a modal form at design time that is displayed later during program execution.
Building this VCL application consists of the following steps:
  1. Create the project directory.
  2. Create two forms for the project.
  3. Link the forms.
  4. Create a control on the main form to display the modal form; then write the event handler.
  5. Build and run the application.
 
This procedure loads a bitmap image from a file and displays it to a VCL form.
  1. Create a VCL form with a button control.
  2. Provide a bitmap image.
  3. Code the button's onClick event handler to load and display a bitmap image.
  4. Build and run the application.
 
This procedure loads a bitmap image from a file and displays it in its entirety to a VCL form. The procedure uses the Height and Width properties of the Bitmap object to display a full view of the image.
  1. Create a VCL form with a button control.
  2. Provide a bitmap image.
  3. Code the button's onClick event handler to load and display a bitmap image.
  4. Build and run the application.
 
This procedure draws a polygon in a VCL form.
  1. Create a VCL form.
  2. Code the form's OnPaint event handler to draw a polygon.
  3. Build and run the application.
 
This procedure draws a rectangle and ellipse in a VCL form.
  1. Create a VCL form.
  2. Code the form's OnPaint event handler to draw a rectangle and ellipse.
  3. Build and run the application.
 
This procedure draws a rounded rectangle in a VCL form.
  1. Create a VCL form and code the form's OnPaint event handler.
  2. Build and run the application.
 
This procedure draws two diagonal straight lines on an image in a VCL form.
  1. Create a VCL form.
  2. Code the form's OnPaint event handler to draw the straight lines.
  3. Build and run the application.
 
You may not want all your VCL application's forms in memory at once. To reduce the amount of memory required at load time, your application can create forms only when it needs to make them available for use. A dialog box, for example, needs to be in memory only during the time the user interacts with it. Using RAD Studio, the following procedure creates a modal form dynamically. The main difference between dynamically creating a form and displaying an auto-created VCL form is that you remove the second form's invocation at startup and write code to dynamically create the form.... more 
A modless form is a window that is displayed until it is either obscured by another window or until it is closed or minimuzed by the user. Using RAD Studio, the following procedure creates a modeless form dynamically.
Building this VCL application consists of the following steps:
  1. Create the project directory.
  2. Create two forms for the project.
  3. Remove the second form's invocation at startup.
  4. Link the forms.
  5. Create a control on the main form to create and display the modal form; then write the event handler.
  6. Build and run the application.
 
This VCL application first creates a list of strings. Then it iterates through the strings, changing all string characters to uppercase. It consists of the following steps:
  1. Create a VCL Form with Buttons and TListBox controls.
  2. Write the code to create a string list and add strings to it.
  3. Write the code to iterate through the string list to process string characters.
  4. Run the application.
 
These are the essential steps to building a VCL Forms multithreaded application with a thread object using RAD Studio. 
 
Use these basic techniques to prevent other threads from accessing the same memory as your thread:
  1. Lock objects.
  2. Use critical sections.
  3. Use a multi-read exclusive-write synchronizer
 
 
 
 
Using the main VCL thread consists of the following basic steps:
  1. Create a separate routine to handle Windows messages received by components in your application.
  2. Call CheckSynchronize periodically.
  3. Declare thread-local variables, as necessary, for exclusive use by your thread.
 
The following are procedures that can be used to wait for threads.
  • Wait for a thread to finish executing.
  • Wait for a task to complete.
  • Check if another thread is waiting for your thread to terminate.
 
The Execute method is your thread function. You can think of it as a program that is launched by your application, except that it shares the same process space. Writing the thread function is a little trickier than writing a separate program, because you must make sure that you do not overwrite memory that is used by other processes in your application. On the other hand, because the thread shares the same process space with other threads, you can use the shared memory to communicate between threads. 
This procedure adds a bitmap image to a combo box in a VCL forms application.
  1. Create a VCL form.
  2. Place components on the form.
  3. Set component properties in the Object Inspector.
  4. Write event handlers for the component's drawing action.
  5. Build and run the application.
 
Creating this VCL application consists of the following steps:
  1. Create a VCL Form with a button control.
  2. Write the code to read the string and write it to a file.
  3. Run the application.
 
Creating this VCL application consists of the following steps:
  1. Create a project directory containing a file to rename.
  2. Create a VCL Form with button and label controls.
  3. Write the code to rename the file.
  4. Run the application.
 
Creating this VCL application consists of the following steps:
  1. Create a VCL Form with Button, Label, and TListBox controls.
  2. Write the code to add and sort strings.
  3. Run the application.
 
Like a Delphi control, an ActiveX control generates program code when you place the component on a form or other logical container in the IDE. The main difference between an ActiveX control and a Delphi control is that an ActiveX control is language independent. You can create ActiveX controls for deployment to a variety of programming environments on Windows, not just Delphi or C++Builder.
This procedure uses the VCL forms ActiveX wizard to create an ActiveX control. To test the control, you can install it on your machine as a VCL component in the IDE. To install the control, you... more 
Like a Delphi control, an ActiveX control generates program code when you place the component on a form or other logical container in the IDE. The main difference between an ActiveX control and a Delphi control is that an ActiveX control is language independent. You can create ActiveX controls for deployment to a variety of programming environments on Windows, not just Delphi or C++Builder, for example.
This procedure uses the VCL forms ActiveX Active Form wizard to create an Active Form containing two components. To test the control, you can deploy it to the Web. This procedure consists of the... more 
Creating the Web browser application consists of the following steps:
  1. Create a VCL Form with a button control.
  2. Add a TWebBrowser component to the form.
  3. Add controls to enter a URL and launch the browser.
  4. Write the code to launch the browser when a button is clicked.
  5. Run the application.
 
This procedure describes how to create an application that uses ribbon controls. The core ribbon functionality is derived from the TRibbon component. While the ribbon uses other components, none of the core components are registered on the tool palette.
Components:
  1. TRibbon: Main visual component that provides most functionality.
  2. TRibbonApplicationMenuBar: Component that provides the functionality of the application menu.
  3. TRibbonQuickAccessToolbar: Component that provides the functionality of the Quick Access Toolbar
  4. TRibbonPage: Component that represents the page of the ribbon that is currently visible
  5. TRibbonGroup: Component that all of the pages commands are displayed in. Commands must be placed in a group.... more 
This topic follows in sequence the creation of a ribbon application using either the Ribbon Application Wizard or the manual steps described in Creating an Application that Uses Ribbon Controls.
This topic assumes that you are familiar with the TActionManager component and the components associated with its use. Numerous new properties have been added to help support the ribbon requirements. Many existing properties have no effect when modified on a command that is displayed on the ribbon.
For instance:
  • Small buttons always display their glyph to the left of the caption.
  • Large buttons always display their glyph at... more 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!