My HMG Learning Experience

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

My HMG Learning Experience

Post by dhaine_adp »

Hi,

This is my approach in learning HMG way back in 2007:

1. I don't go into programming right away. I set aside time to first read HMG manual, how it is organize and how I would quickly cross reference the manual. My goal is to familiarize myself with the documentation so I know where to find them.

2. Then I check how Harbour (without HMG and no third party clipper library), can compile pure Clipper code. Then I wrote code to to test RDD (DBFCDX) from my old application, basically the routine that opened the tables, replaced field contents, seek, delete, array handling, numeric calculation, date calculations. All those are done without data entry screen (because that will be the GUI portion). So when I found out that Harbour can do all those, I am quite sure that I only needed to learn how to manage the GUI portion and learn the technique of interfacing HMG+Harbour. For Harbour reference I used Clipper reference books and the NGs and reading those CHANGELOG.TXT of Harbour, HMG and HMG Extended to at least piece together what's going on and to get an insight and somehow connect to the developers mind (those logs are their first hand account, just like a diary if you will).

3. To learn HMG I used <hmgInstallDir>\SAMPLES\Basics\MAIN_DEMO\DEMO.PRG. Of course if you are looking for something you've needed a demo that showcase everything (at least most of it if not all).

4. On the third week I have my old app reborn in HMG+Harbour, though its not fully bug free but I'd be able to smooth them out later on. The rest is history.

5. Since HMG is an open source and evolving, I/we should understand that there won't be a book like manual anytime soon. So you need to read the include files and the corresponding c and prg modules of the library (which became my second HMG reference). You can do this to further enhanced your knowledge.

6. Use modular programming as much as possible. Since Clipper days I wrote code in modular way (if possible) so when I moved to HMG I basically change the Text User Interface with GUI or forms. Now the @ SAY commands becomes LABEL and @ GET becomes TEXTBOX plus the COMBOBOX, RADIOGROUP, CHECKBOX, etc.

7. Coding in GUI means to forget about SAVESCREEN() and RESTSCREEN(). You need to have a new paradigm which is event driven. Restrict the user to a form by using modal or even then you can prevent it by attaching procedures to ON RELEASE and ON INTERACTIVECLOSE.

8. HMG Controls resembles VB but not exactly the same. So in essence the key in learning HMG is understanding HMG controls and objects EVENTS and PROPERTIES which is contained in the manual. Those are the points to where you can interface your Clipper knowledge towards Harbour and HMG. Later on if you think that you have the feel of it, then exploit to your advantage.

Tips:
1. Event driven programming is not the same as procedural programming so don't let the frustration bugs you down. See it as a challenge to be overcome. Everybody (in this [HMG] Forum, HMG Extended and Harbour users) did it that way and there's no reason that you can't.

2. Program Control Flow: In order to control your program flow, learn or read the HMG manual regarding the EVENTS or METHODS (same as events) and PROPERTIES of a control that you intended to use. Most of HMG control objects have a common EVENTS like ON LOSTFOCUS, ON GOTFOCUS and ON CHANGE. Forms (Windows) have much more EVENTS like ON INIT, ON GOTFOCUS, ON SIZE, ON MAXIMIZE, ON RELEASE, ON INTERACTIVE CLOSE (windows close box), etc. Those events are functions, procedures or code blocks that you attached to them called branching out or (threads). Threads and subroutines has a thin red-line difference but equally alike. So do not release the window from triggered events unless that's your intention. Remember to use setfocus (to a form or to a control object) if you need to and really you needed to do that to control the program flow.

So before you code plan ahead and determine how are you going to control those EVENTS that ultimately defines the behavior of your application. Those events are our/your friend as well as a foe. It will be easier to go over with the samples and start building from there. Eventually incorporate your routines from simple and progressively going to a complex one.

Use HMG-IDE to compile and debug and to watch how the codes are executed one after the other. Step through it by using F8. Insert ALTD() to any position in your source code to pause or stop the debugger. To run in debugger mode from HMG-IDE click Project->Debug (select debug).

3. If your program does different than your intended goal or design, create a small test version and test if they are the same. Almost always the problem is in your code and not in the library. Otherwise post them to HMG Forum describing your problem in details.

IMHO, HMG and HMG Extended has a short learning curve but that depends on how are you going to approach your migration to HMG. From Clipper I believed that would be about the GUI handling. From FoxPro (DOS/Windows) read Harbour's RDD, AEVAL(), EVAL(), functions and code blocks, variable types and data types and HMG manual.

Learning is fun and I am quite sure that as you progress you can code a simple straight forward form without using the form designer. For me I define the labels height as 18 and textboxes as default height which is 24 and default width. I added 3 on the labels row based on the row that I used on textbox control like the code snippet below:

Code: Select all

DEFINE WINDOW frmGUI_1 AT 0,0 WIDTH 409 HEIGHT 185;

@  33, 30 LABEL lblCode OF frmGUI_1 VALUE "&Code:"; 
ACTION Nil WIDTH  70 HEIGHT 18 FONT "Arial" SIZE 9
               
@  30,120 TEXTBOX txbCode OF frmGUI_1 HEIGHT 24 VALUE ALLTRIM( COLTBL->F1 ) READONLY WIDTH  100;
FONT "Arial" SIZE 9 TOOLTIP "" MAXLENGTH 10 UPPERCASE;
ON LOSTFOCUS CheckEventLostFocus( cMode )
               
@  63, 30 LABEL lblDesc OF frmGUI_1 VALUE "&Name:"; 
ACTION Nil WIDTH  70 HEIGHT 18 FONT "Arial" SIZE 9               
               
@  60,120 TEXTBOX txbDesc OF frmGUI_1 HEIGHT 24 VALUE ALLTRIM( COLTBL->F2 ) WIDTH  250;
FONT "Arial" SIZE 9 TOOLTIP "" MAXLENGTH 40 ON LOSTFOCUS CheckEventLostFocus( cMode );
ON CHANGE GUISaveButtonEnable()
From those coordinates that you've specified you can figure out the dimensions (at run-time). That comes handy if you are on a client's site and needed to accomodate a minor adjustments in the form or to a complex form or simply if you want to speed up your program coding. Furthermore, you can create your own tool(s) to help you in your HMG programming.

HMG Tutorial by Giovanni Di Maria: http://www.elektrosoft.it/tutorials.asp
Kevin Carmody's HMG manual in CHM format: http://kevincarmody.com/hmg/DOC/
You can also visit HMG Extended (forked from HMG) at: http://www.hmgextended.com/
You can find more at Mr. Esgici's Blog at: http://vivaclipper.wordpress.com/

Sample HMG-IDE Configuration

Code: Select all

# HBMK2 : link script
# Author: Danny Del Pilar
#
#################################

#include Paths
incpaths=c:\hmg\include

#library paths
libpaths=c:\hmg\lib
libs=valleylibs daleaidcommon

#Resulting Executable Folder
instpaths=

#Build Options
mt=yes
inc=no
head=native
Sample HMG-IDE Resources Definition to burn-in the image files in the executable file. The project folder were structured like this:
<ProjectFolder>
source1.prg
source2.prg
source3.prg
:---- data
:---- res
:---- doc
:---- deprecated
:---- notes

Code: Select all

MAINICON ICON RES\SCFICON.ICO
IMGTBEXIT BITMAP RES\EXIT.BMP
IMGEXIT16 BITMAP RES\EXIT16.BMP
IMGEXIT32 PNG RES\EXIT32.PNG
IMGBKUP BITMAP RES\COMPRESS.BMP
IMGCOMP32 PNG RES\COMPRESS32.PNG
IMGRBRES BITMAP RES\RESTORE.BMP
IMGRBRES32 PNG RES\RESTORE32.PNG
IMGEXPLORE BITMAP RES\EXP.BMP
IMGEXPLORE32 PNG RES\VIEW32.PNG
IMGLOGOFF BITMAP RES\TBLOGOFF.BMP
IMGLOGOFF16 BITMAP RES\LOGOFF16.BMP
IMGPEOPLE BITMAP RES\PEOPLE.BMP
IMGCOL16 BITMAP RES\TBCOLLECTION16.BMP
IMGCOL32 JPG RES\COLLECTION32.JPG
IMGCRED16 BITMAP RES\CREDITORS.BMP
IMGCRED32 JPG RES\CREDITORS32.JPG
SCFBANNER PNG RES\SCFBANNER2.PNG
IMGDEP216 PNG RES\DEPOSIT2.PNG
IMGEXP16 PNG RES\EXPENSES.PNG
IMGEXP32 JPG RES\EXPENSES32.JPG
IMGLOGIN PNG RES\scflogin.PNG
IMGTBLOG PNG RES\scflogin32.png
IMGCOLLECT PNG RES\money_bag2.png
IMGDISB PNG RES\DISBURSE.PNG
IMGDISB32 PNG RES\DISB32.PNG
IMGLOANREG PNG RES\LOANREG.PNG
IMGLOANREG32 PNG RES\loanregistry32.png
DADEXIT BITMAP RES\EXIT20.BMP
DADNEW16 BITMAP RES\NEW_FIELD16.BMP
DADEDIT20 BITMAP RES\EDIT20.BMP     
DADDEL BITMAP RES\DELRECORD16.BMP
DADPRINT16 BITMAP RES\PRINT16_2.BMP  
DADNEW BITMAP RES\NEW_FIELD.BMP  
DADEDITFIELD BITMAP RES\EDIT_FIELD.BMP 
DADCANCEL BITMAP RES\CANCEL.BMP
DADOK BITMAP RES\OK.BMP     
DADPRINT BITMAP RES\PRINT.BMP
DADFIND BITMAP RES\FIND.BMP
DADSTRUCT BITMAP RES\STRUCT.BMP
/*--------------------------
Metadata
----------------------------*/
1 VERSIONINFO
FILEVERSION     1,0,0,0
PRODUCTVERSION  1,0,0,0
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904E4"
    BEGIN
      VALUE "CompanyName", "La DALE-Aid® Creative Solutions"
      VALUE "FileDescription", "Cash Flow Lite Version 1.0"
      VALUE "FileVersion", "1.0"
      VALUE "InternalName", "SCF"
      VALUE "LegalCopyright", "Danny A. Del Pilar"
      VALUE "OriginalFilename", "scf.exe"
      VALUE "ProductName", "Cash Flow Lite Version 1.0 (Simple Cash Flow Management System)"
      VALUE "ProductVersion", "1.0"
    END
  END

  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x409, 1252
  END
END
Regards,

Danny
Manila, Philippines
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: My HMG Learning Experience

Post by esgici »

Wonderful !

Many thanks Danny :)

Would you permit me for publish this article on my blog ? :oops:

TIA
Viva INTERNATIONAL HMG :D
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: My HMG Learning Experience

Post by dhaine_adp »

Would you permit me for publish this article on my blog ? :oops:
That would be great. Please go ahead.
Regards,

Danny
Manila, Philippines
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: My HMG Learning Experience

Post by esgici »

dhaine_adp wrote: That would be great. Please go ahead.
Thanks, done :!:

Regards
Viva INTERNATIONAL HMG :D
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: My HMG Learning Experience

Post by Javier Tovar »

Hola Danny,

Estas inspirado... Sigue así. :) ;) :o

Saludos

///////////////////////////////////////////////////////////////////////////////
Hi Danny,

These inspirational ... Keep it up. :) ;) :o

regards
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: My HMG Learning Experience

Post by esgici »

..........
Last edited by esgici on Tue Feb 20, 2018 12:22 am, edited 1 time in total.
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: My HMG Learning Experience

Post by Rathinagiri »

Danny, just now I had got the opportunity to read this post. It is really wonderful to read your experience.

Hope this helps every HMG beginner. I am making this topic sticky.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: My HMG Learning Experience

Post by mol »

Great! It would be very good article for beginners!
Thanks!
User avatar
quartz565
Posts: 667
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Contact:

Re: My HMG Learning Experience

Post by quartz565 »

Very nice!!
Thank you Danny!
Best Regards,
Nikos.

os: Windows Server 2019 - 64
Zimbo
Posts: 56
Joined: Mon Nov 05, 2012 1:28 pm
Location: Scotland
Contact:

Re: My HMG Learning Experience

Post by Zimbo »

Nice one, Danny! I guess there are a few of us trying to produce a guide or an aid to get others using Harbour and HMG. It's such a great and powerful language and a real shame its only attracted a 'clique' audience.

Zim
Post Reply