Basic Controls – 2

( Text Box  )

We are continuing with Viva_HMG.hbp, Main.prg and Main.fmg. We have assign real actions other than MsgBox() to our two buttons now : Open File and Edit Record. Open File not required GUI controls ( at least for now ), so we can begin with it: For Open File we need a file ( a table ) first: it’s here; a table with four field: Clients.dbf :

No:  Field Name Type Width Dec
---  ---------  ---- ----- ---
  1  CLI_ID       N      5   0
  2  CLI_SNAM     C     12   0
  3  CLI_NAME     C     12   0
  4  CLI_TLF      C     11   0

And then add a little routine to Main.prg for open (USE) it:

      MsgStop( "Clients.dbf file not found !")
RETURN // OpenTable()

And assign this procedure to ACTION of  Open File  button.

Now, we can begin Edit Record task. For this task we need a separate form, a sub form.  Then let’s begin. “New form” from tool-bar and assign a name : EditReco. Assign a title : “Edit Record”, a type : MODAL. Our table has four fields, so we need four LABEL first:

Names :  lblCLI_ID,  lblCLI_SNAM,  lblCLI_NAME, lblCLI_TLF;

Values ( Captions ) : ID,  Surname, Name, Tlf

Rows : 60, 100, 140, 180 Col : 60

Cols :  60, 60, 60, 60

Widths : 70, 70,  70, 70


We can see our job at work:

Now we need a place  for display the current data and accept user input. The control for this purpose is text box. So we need to define four text boxes for each field in the table.

The button of text box in the IDE tool bar is :

Names :  txbCLI_ID,  txbCLI_SNAM,  txbCLI_NAME, txbCLI_TLF;

Rows : 55, 95, 135, 175

Col : 140

DataTypes : First : NUMERIC, others : CHARACTER

We can see our job at work:

Well …

But where are table data ?

To see table data we need assign field values to text boxes as values.

Again, a little procedure:

   EditReco.txbCLI_ID.Value   := CLIENTS->CLI_ID
   EditReco.txbCLI_SNAM.Value := CLIENTS->CLI_SNAM
   EditReco.txbCLI_NAME.Value := CLIENTS->CLI_NAME
   EditReco.txbCLI_TLF.Value  := CLIENTS->CLI_TLF
RETURN // ReadData()

and a call command for this procedure to ON INIT event of  EditReco form.

The result :

Everything is OK ?

No !

This is only first record of table; how we will see others ?

Yes, we need now yet another feature: navigation; that is travelling between records of table.

But before navigation, we have a problem: Open Table must be processed before Edit Record.

Otherwise a run time error will occurs: Alias does not exist. 

What we can do?

–       Discard Open Table button, open the table automatically; at beginning of program or at beginning of editing.

–       Before editing, check the table, if doesn’t open,

–          a)  open automatically or

–          b)  warn user and don’t load Edit Table form.

Probably most convenient is : disable Edit Record button until table is open.

First a mini procedure :

PROCEDURE Initialize()
   Main.btnEditRec.Enabled := .F.
RETURN // Initialize()

And then add this procedure ON INIT event of form main:

Last point: enable it after USE table:

      Main.btnEditRec.Enabled := .T.
      MsgStop( "Clients.dbf file not found !")
RETURN // OpenTable()

Run and see:

Before Open File :

After Open File:

Now we can pass to navigation:

We need seven buttons: Go Top, Go Next, Go Previous, Go Last, Save, Discard, Exit.

Name: btnGoTop, Caption : Top,  Col : 50, Row: 220, Height: 28, Width: 60

Name: btnGoNext, Caption : Next,  Col : 130, Row: 220, Height: 28, Width: 60

Name: btnPrevious, Caption : Previous,  Col : 200, Row: 220, Height: 28, Width: 60

Name: btnGoLast, Caption : Last,  Col : 270, Row: 220, Height: 28, Width: 60

Name: btnSave Caption : Save,  Col : 380, Row: 60, Height: 28, Width: 100

Name: btnDiscard, Caption : Discard,  Col : 380, Row: 140, Height: 28, Width: 100

Name: btnExit, Caption : Exit,  Col : 380, Row: 220, Height: 28, Width: 100

Common: Font Name: Tahoma, Font Size: 9

Actions :

btnGoTop: ( DBGOTOP(), ReadData() )
btnGoNext: ( DBSKIP(), ReadData() )
btnPrevious: ( DBSKIP( -1 ), ReadData() )
btnGoLast: ( DBGOBOTTOM(), ReadData() )
btnSave: SaveData()
btnDiscard: ReadData()

btnExit: ThisWindow.Release

Note that actions of four first buttons include two actions, separated by comma and enclosed by parenthesis.  With this notation we can define more than one action together.

SaveData() is the inverse of  ReadData(): copy values of text boxes to table fields.

PROCEDURE SaveData()         // Save data from text boxes to table
   CLIENTS->CLI_ID   := EditReco.txbCLI_ID.Value
   CLIENTS->CLI_SNAM := EditReco.txbCLI_SNAM.Value
   CLIENTS->CLI_NAME := EditReco.txbCLI_NAME.Value
   CLIENTS->CLI_TLF  := EditReco.txbCLI_TLF.Value
RETURN // SaveData()

Discard is simply re-reading data from table.

The result:

To be continued …

Download source files


Mini Agenda

This is a mini application developed primarily to denote some wonderful features of HMG.

Mini Agenda uses:

– A text (csv)  file for data source and Grid as browse of this file

– DEFINE ACTIVEX for “About” page from a .html file

– HFCL library ( Thanks to S. Rathinagiri for GridPrint )

Features :

– File operations: New, Open, ReOpen, Close, Save, Save as, Print

– Record operations:  Append, Delete, Insert

– Three way ( Natural, Ascending, Descending) sorting columns

– Preserve current item after sort

– In_place editing

– Incremental (and “soft” ) Search

– .ini File for keeping record of last used data file

Download : source, executable.

Browse by IDE

BROWSE is a control a few complicated than others. However HMG-IDE successfully support it.

In this sample we will build a Browse based application in a few steps using HMG-IDE.

Step – 1 : Make a folder for this sample.

Step – 2 : Copy TEST.DBF and TEST.DBT from \hmg\SAMPLES\TUTORIAL folder to your new folder.

Step – 3 : Run HMG-IDE and chose “New Project”.

IDE will ask you location and name for the new project; denote the folder you had build in the first step and give a name, say “IDEBrowse”.

IDE will build a new main module named “Main.Prg” and a new main form named “Main.fmg”

Step – 4 :

Double click “Main.prg” in the “Modules” tab of “Project Browser” window for editing this “main” module:

IDE send this module (.prg) file to your programing editor.

You will see your main program written by IDE :

#include <>

Function Main
 Load Window Main

Step – 5 :

Since BROWSE is a table based control, we must have a table and files opening/closing routines; these aren’t duties of IDE.

So add this two little procedures to the main.prg for opening and closing table:

Procedure OpenTables()
Use Test Shared
Procedure CloseTables()

 Step – 6 :

Now, it’s time for making some arrangements on the form:

Title :

– Click  “Object Inspector [Main.Fmg]\Form\Properties\Title” :

– Give a “Title”, say “IDE Browse Sample” to form :

On Init Procedure :

– By clicking “Object Inspector [Main.Fmg]\Form\Events\OnInit” ;

– Assign OpenTables() procedure name to this event:

On Release Procedure :

– By clicking “Object Inspector [Main.Fmg]\Form\Events\OnRelease”;

– Assign CloseTables() procedure name to this event:

Step – 7 :

Now, we can place BROWSE control in our form:

– Click BROWSE button in the Toolbox:

– Then click anywhere in the form :

– Re-size control by dragging “resize” mark at the lower rigth corner :

 – If required, change placement of control by using “replace” mark ( at the upper-left corner )


– By using these two marks, you can place control in the form whatever you like:

 Step – 8 :

And now, we will make some arrangements on the BROWSE control :

After activating ( by clicking on it ) BROWSE control;

By selecting “Object Inspector[Main.Fmg]\Browse_1\Properties” give these properties to Browse_1 control:

– “Fields” property :


– “Headers” property :

{ ‘Code’, ‘First Name’, ‘Last Name’, ‘Birth Date’, ‘Married’, ‘Biography’ }

– “Widths” property :

{ 150, 150, 150, 150, 150, 150 }

– “Work Area” property :


Note that “array” properties requires open and close curly-braces (‘{}’),  character properties doesn’t requires quotation marks (“”).

If you want allow editing  abilities to user, you have change default values (.F.) of these properties to .T.


Last Step :

That is All !

Click “Run” button ( or select “Run” from Project menu or simply press F5 key) for see results :

You have now a BROWSE based HMG application generated  by IDE.

When you use “Run” command or attempt to closing   your form by clicking “X” button, IDE ask you saving it ( if any change you have made ). You may also use Project\Save Form menu command.

Since IDE is a “Two-Way Form Designer”, you can edit .fmg files by double clicking its name in the “Forms” tab   of “Project Browser” window.

And since .fmg files are pure HMG source code, you can open a .fmg file by your editor to see  form source  code generated by IDE. Inspecting this code may be useful for better understanding and learning HMG.

You can also edit this file manually, but under your own risk ! Some modifications may not suitable to the standards of Form Designer.