Tutorial: Hello World
In this tutorial you will build your very first HarbourBuilder application from scratch — a simple window with a button that displays a greeting. By the end, you will understand the basic project workflow: create, design, code, build, and run.
Step 1: Create a New Project
- Launch HarbourBuilder.
- Select File → New Project from the menu bar.
- In the New Project dialog, choose a folder (e.g.
C:\Projects\HelloWorld) and enter the project nameHelloWorld. - Click OK. The IDE creates a
HelloWorld.hbpproject file and amain.prgsource file with a starter template.
HarbourBuilder creates a clean folder with your .hbp project file and a main.prg source.
All compiled output goes into a build/ subfolder that you can safely add to .gitignore.
Step 2: Open the Form Designer
- In the Project Manager panel, double-click
main.prg. - The Form Designer opens showing an empty form titled "My First App".
- The Object Inspector on the left displays the form's properties.
- Change the
cTitleproperty to"Hello World"and press Enter — the form title bar updates immediately.
Step 3: Add a Button
- Click the Standard tab in the Component Palette at the top of the IDE.
- Click the Button icon in the palette.
- Click on the form surface near the center — a button appears.
- In the Object Inspector, set the button's
cPromptproperty to"Say Hello". - Optionally adjust the
nTop,nLeft,nWidth, andnHeightproperties to position and size the button.
Step 4: Add a Label
- From the Standard palette tab, click the Label icon.
- Click on the form above the button to place the label.
- Set the label's
cValueproperty to"Click the button below!". - Set
nWidthto300so the text fits comfortably.
Step 5: Set the OnClick Event
- Select the button on the form (click it once).
- In the Object Inspector, switch to the Events tab.
- Double-click the
OnClickevent row. The IDE switches to the Code Editor and creates a handler stub. - Fill in the handler so it updates the label text:
oBtn:OnClick := { || oLabel:SetValue( "Hello from HarbourBuilder!" ) }
For simple one-liners, an inline code block { || ... } is perfect. For more complex logic,
call a separate static function from the block. See the Event Handling tutorial for details.
Step 6: Build and Run
- Press F9 (or select Run → Build & Run).
- Watch the Messages panel at the bottom — it shows preprocessing, compiling, linking, and launching steps.
- Your application window appears. Click the "Say Hello" button.
- The label text changes to "Hello from HarbourBuilder!".
Full Code Listing
Here is the complete main.prg for the Hello World application:
#include "hbbuilder.ch" function Main() local oForm, oBtn, oLabel DEFINE FORM oForm TITLE "Hello World" ; SIZE 640, 480 FONT "Segoe UI", 10 @ 30, 50 LABEL oLabel VALUE "Click the button below!" ; OF oForm SIZE 300, 24 @ 70, 50 BUTTON oBtn PROMPT "Say Hello" ; OF oForm SIZE 120, 32 ; ACTION oLabel:SetValue( "Hello from HarbourBuilder!" ) ACTIVATE FORM oForm CENTERED return nil
What You Learned
- How to create a new HarbourBuilder project.
- How to use the Form Designer to place controls visually.
- How to set properties via the Object Inspector.
- How to wire up an
OnClickevent handler. - How to build and run your application with F9.
Ready for more? Continue to the Working with Forms tutorial to learn how to create multi-form applications with modal dialogs and data passing between forms.