Building a Windows VCL Hello World Application
Go Up to How To Build Windows VCL Applications
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:
- Create a VCL Form with a button control.
- Write the code to display "Hello world" when the button is clicked.
- Run the application.
To create a VCL Form
- Choose File > New > Windows VCL Application - Delphi or Windows VCL Application - C++Builder .
- Click the VCL form to display the form view.
- From the Standard page of the Tool Palette, place a TButton component on the form.
To display the "Hello world" string
- Select Button1 on the form.
- 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.
- 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.
- For Delphi, insert the cursor on the new line created, and type the following variable declaration:
var s: string;
- For C++, enter the following code:
AnsiString s;
- For Delphi, insert the cursor within the code block and type the following code:
s:= 'Hello world!';
ShowMessage(s);
- For C++, enter the following code: s = "Hello world!";
ShowMessage(s);
To run the "Hello world" application
- Choose Run > Run to build and run the application.The form displays with a button called Button1.
- Click Button1. A dialog box displays the message "Hello World!"
- Close the VCL form to return to the IDE.