RAD Studio |  |

Building a VCL Forms "Hello World" Application
See Also
Collapse All

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.

To create a VCL Form

1. Choose FileNewOtherDelphi Projects or C++Builder Projects and double-click the VCL Forms Application icon. The VCL Forms Designer is displayed.
2. Click the VCL form to display the form view.
3. From the Standard page of the Tool Palette, place a TButton component on the form.

To display the "Hello world" string

1. Select Button1 on the form.
2. In the Object Inspector, double-click the OnClick action field on the Events tab. The Code Editor displays, with the cursor in the Button1Click event handler block.
3. For Delphi, move the cursor before the begin reserved word and then press ENTER. This creates a new line above the code block. For C++, place the cursor after the opening brace ({) and press ENTER.
4. For Delphi, insert the cursor on the new line created, and type the following variable declaration:

Copy Code

    var s: string;

For C++, enter the following code:

Copy Code

    AnsiString s;

1. For Delphi, insert the cursor within the code block and type the following code:

Copy Code

    s:= 'Hello world!';
    ShowMessage(s);

For C++, enter the following code:

Copy Code

    s = “Hello world!”;
    ShowMessage( s );

To run the "Hello world" application

1. Choose RunRun to build and run the application. The form displays with a button called Button1.
2. Click Button1. A dialog box displays the message "Hello World!"
3. Close the VCL form to return to the IDE.

See Also

VCL Overview

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!