MOL (Marek Olszewski)

Contributed samples by MOL (Marek Olszewski)

Backup-Restore

Billing System ( definable buttons )

Calculator

Copy To Clipboard

Deactivate menu

Debug Message

Download from www

EAN13 BarCode Generator

Filter in Browse

HMG with MS SQL server

Incremental Search in BROWSE 

Menu like ACHOICE

Moldruk (Print like DOS )

Set Status Bar Item

Send mails via SMTP

Using ProgressBar as a graph

Quick Start to Migration

Chapter I – Text to text conversion

In Clipper world, “migration” means “convert a DOS based Clipper program to Windows”. This is a dream of every Clipper – DOS programmer.

 Before all, we need clarify some terms:

May be found multiple ways for convert a DOS based Clipper program to Windows. In general, DOS programs are runs in “text” mode and Windows program runs in “Graphic” mode; and this is what meant by term “migration”.

Converting a text mode program to directly GUI (Graphical User Interface) is a painful job. First, we need to find a Compiler with GUI support, or a GUI library usable with a specific compiler. If we have more than one opportunity ( yes, it is so ) we need make a choice between them.

For make a right selection we need learn, understand specialties of each option and differences between them.

Believe me, this is an endless way 😦

Instead, let’s begin with simpler thing: convert a DOS text mode program to Windows text mode program.

Question: Without GUI, what meaning will be to migrate from DOS to Windows?

Answer: Good question and like all good question, answer isn’t easy.

First, modern OSs moves away day to day from DOS conditions; memory problems, screen problems, codepage problems, etc… By the time, building / running 16 bit executable becomes more difficult day to day.

Whereas Harbour already is a 32 / 64 bit compiler.

Second, all DOS Compilers for Clipper are commercial and registration required products; furthermore they are almost out of sold for this days; what compiler you could use?

And third, Harbour is best free compiler and the best way to use a free GUI tool for xBase language.

So, beginning with using Harbour in text mode is the best start point, I think.

First step is downloading and install HMG or Harbour. If you didn’t past this step yet please refer previous articles in this section or “Links” page of this blog.

The easiest way for using Harbour compiler is calling hbmk2, the wonderful project maker for Harbour compiler.

Depending your installation, hbmk2 may be in different locations; such as C:\Harbour\bin or c:\hmg\harbour\bin or anything else.

Hereafter I will assume that your hbmk2 is in C:\hmg\Harbour\bin. If your installation is different, please modify above examples.

Second step is assign an empty folder (directory) for work / test affairs; say C:\test.

And the third step is copying your Clipper program(s) to this folder.

But don’t rush; we have some precautions:

– Better way is starting with a single-program project; if you haven’t written a new one. Don’t uses for now projects have multiple program file.

 – Your program may have some “national” characters and these characters may be differently shown between DOS and Windows. If so, you may want fix manually these differences via a Windows based text editor. Or use a program if you have one. Harbour has a clever tool (HB_OEMTOANSI() function) is usable for this purpose.

 – In Clipper it’s possible a program file without module (procedure / function) definition. If you have such file(s), enclose your code with PROCEDURE — RETURN statement pair.

– Every Harbour project must have one and only one MAIN module (procedure / function). The first procedure / function in your single program file will be considered as MAIN module of your project. (In HMG, name of this module must be “main” also).

– Almost all Clipper commands, statement, functions, pseudo functions, manifest constants etc are usable almost in the same ways with Clipper. May be exist some very few and very rare differences, and of course solving methods for its.

For compile process we will use command box (DOS / console window) of Windows. You can open a console window, with the menu Start -> Run -> cmd or selecting it in the “Command Prompt” from the Start Menu \ All Programs.

 – “Command / console window” size may not appropriate for easy use. You may

      – use a MODE ( DOS ) command :

         MODE CON LINES=54 COLS=148

       or

   – adding a SetMode() statement at the beginning of MAIN module of your project. For example:

       SetMode( 25,  80 )  // 25 line 80 column same as standard 
                           // DOS screen ( but not full screen ! )
       SetMode( 48, 128 )  // 48 line 128 column, may be more readable

Now, we are ready to begin: Enter this command in console window :

 C:\hmg\harbour\bin hbmk2 <mainPrgName>

You don’t need any SET command (such as PATH etc) before this command; hbmk2 will find all necessary paths / files.

For running executable after compile, add a -run switch to the command line :

 C:\hmg\harbour\bin hbmk2 <mainPrgName> -run

Of course, you need supply name of your main .prg file in place of <mainPrgName>.

Note that you don’t need a separate “linking” step; hbmk2 will do everything for you.

You may use this

 C:\hmg\harbour\bin hbmk2 <mainPrgName>

command via a batch ( .bat ) command file (such as “build.bat”) too. In this way you can apply compiling process without console window; run .bat file by double click in the Windows Explorer. In this case you may need add a PAUSE command at end of .bat file.

That’s all.

You know, a program file may contains more than one module (procedure / function). So you may develop your project by adding new modules to your single program file.

In this step you don’t need trying extra features, extensions of Harbour. Before that adventure your primary need is to convert existing project Clipper to Harbour.

When you reach a level of multiple-program file project:

– Basic rules are the same: the first module in the your program file is MAIN module of your project.

If your .prg files contains:

  SET PROCEDURE TO <procedure_File_Name>

 and / or

   #include <procedure_File_Name>

 you may or may not continue using these statement.

 – The shortest way for compiling a multiple-file project is use a .hbp ( Harbour Projet ) file. This is a text file and its simplest form is a file contains list of your .prg files. For example:

myprog01.prg
myprog02.prg
myprog03.prg
myprog04.prg

and the compile command is the same :

  C:\hmg\harbour\bin hbmk2 <mainProjectFileName>

In this case you don’t need to use SET PROC… and #include … statement and this is the better way.

Because hbmk2 applies “incremental” compiling, that is compiles only modified files.

Under normal circumstances, any module in any program file is callable in anywhere in the project. If you have some modules that exclusive to this program file, you may use STATIC keyword at the beginning of PROCEDURE / FUNCTION statement. For example:

STATIC FUNCTION OpenTable()

With this syntax you will prevent calling this module outside of this .prg file and the possibility of using this module name into other .prg files.

Example :

Take “A typical Harbour Program” in the “Harbour Sample” page.

As seen at .pdf file by given link, this sample program borrowed from official reference guide of a Clipper compiler. That is, in fact this is a Clipper program and it will may compile with Harbour and run without any modification.

Let’s try.

– Copy and paste this sample and save in your PC with a name say “typical.prg”.

– Comment out the line for now.

 #include "Database.prg" // Contains generic database functions

– Call hbmk2:

 C:\hmg\harbour\bin hbmk2 typical -run

 Note: While working / playing on programs, you may encounter some error messages like:

  Error F0029  Can't open #include file xxx
  Error E0002  Redefinition of procedure or function xxx
  Error: Referenced, missing, but unknown function(s): xxx
  undefined reference to HB_FUN_xxx

 Please don’t panic !

    “Error” is salt and pepper of programming play ! 😉

 The worst situation isn’t getting error, but is unable to stay !

   The “HB_FUN_xxx” may be seen weird at first meet. The “HB_FUN_” is a prefix given by system ( compiler ) to your function; so you need search erroneous point into tour program files without this prefix.

Now, let’s continue to our “typical” program:

If you compile the program with commented out #include … line, possibly it will work, by opening main menu:

Typical_1

But what’s that?

When selected a menu item (except “Quit”) we can’t see other than an empty screen!

Again, don’t panic!

This situation too is not very rare !

If you use vertical scroll bar of command / console window, you will notice that your screen is considerably much longer than seen !

To avoid this conflict, ( as stated above ) we need use a SetMode() function call at top of our Main() procedure ( but AFTER LOCAL statement ! ) :

  SetMode( 24, 79 )

 And now everything is OK.

Typical_2

In fact, not really everything, we have a few “fine adjustment”.

Cut and paste the section after “// Database.prg” to a separate “Database.prg” file, un-comment the “#include …” line and then re-compile.

In this case we have a “multiple prg” project. As stated earlier, better way is using a .hbp file instead of “#include …” statements.

Now comment out ( or delete now ) the #include line.

Build a new text file with name “typical.hbp” and with this content :

Typical.prg
DataBase.prg

And recall hbmk2 without any modification :

C:\hmg\harbour\bin hbmk2 typical -run

That’s all !

Congratulations !

Now you have a multiple-prg project  !

What is HMG ?

( By Roberto Lopez, builder of HMG )

Well.. for the new people approaching HMG I can say that this is a mix between one of the best programming and data manipulation languages ever created (xBase) and the VB/RapidQ GUI handling style.

All GUI object are public and can be created and managed with very simple code.

The basic components of HMG are:

– Harbour Compiler (generates C code from xBase code).

– Harbour MiniGUI library (functions and preprocessor directives to handle GUI).

– MingW Compiler.

– Harbour MiniGUI IDE (Optional tool for two-way visual design).


What are the main project goals ?

To keep the GUI handling as easy, elegant and clean as possible and the
library core as compact, stable and reliable as we can.

It implies, that the changes to the core will be subject to very strict test
prior tag a specific build as ‘stable’.

Other of the main goals is to hide the complexities associated with the
operating system internals, allowing to the programmer, focus on his
application, instead OS technical things.

So, what is the place for experimentation and exciting new ‘things’ ?

The User components interface, of course.

I’ve created to let to any HMG user to add fully new GUI elements, or add
properties and events to existing ones.

Where is the HMG site ?

http://harbourminigui.googlepages.com

Where can I download HMG ?

http://harbourminigui.googlepages.com

Why Roberto doesn’t answer my messages ? :)

I have a very little free time for HMG right now. Anyway I’m reading
and answering the Sorceforge’s HMG bug tracker and Wish tracker,
almost daily, please use it.

Does HMG will be ‘real’ OOP some day in the future ?

Who knows :)

What about user contributions? 

I’ve noticed about comments like “Roberto does not accept code contributions
anymore“.

This is true, but need some clarification.

In 2005 I’ve decided to change the way I work on minigui.

From that moment I do all modifications to the library personally, but I still receiving comments, suggestions ideas and wishes from the users.

The reason for this, is that I want to keep the control of the code included in the library, to assure that it remains compact, fast, stable, reliable and backwards compatible, keeping and eye on general project goals (enumerated in the previous message).

An example of this, is the recent Activex addition.

I’ve noticed that this feature was incorporated to the Freewin project.

I’ve analyzed the code, learned how it works ant then rewrote it
from the scratch to suit minigui library needs.

This way, I’m not incorporating a ‘black box’ to the library that
could be difficult or impossible to fix or modify. I’m incorporating
code that is simple and easy to maintain.

I can make mistakes and write buggy code (of course) but there is a big possibility that I’m be able to fix it, since I’ve wrote it.

So, You can send to me (to HMG wish tracker at SourceForge) sample code with your propossed addition. I’ll take a look at it.

What about other MiniGUI based projects… ?
Why do not all MiniGUIs guys unite and work together ?

I’ll could add another question:

Why the humanity does not unite and work together? :)

Well… I apreciate and respect a lot to Grigory, Jacek and Janusz from MiniGUI Extended and to Ciro and Vicente from OOHG. All of them are doing a great work, but simply we have different opinions about of what MiniGUI has to be. Thats all.

This is very good for users, since they have three alternatives to choice.

I feel very honored because two new projects emerged from my original work.

Why do not add to library a nice widget that do something… ? it could be good for my application that needs it.

I could write now a long explanation about the need that the features added to the core library must be generic, designed to fill the needs of most common programming situations and not to solve a specific user’s problem.

Fortunately you could get the Simpsons episode 7F16 :)

In this episode Homer designs a car to suit his own needs. Of course, the car was a monstrosity very expensive and (of course) a complete failure.

Perhaps there is no need to watch the episode to get the idea, maybe that this image be enough:

homer-car

If the idea is not clear enough yet, here is a little explanation:

Adding lot of things, designed to suit specific (very unusual situations) to the library core, will give us a fat, slow, buggy and difficult to learn GUI system. I’ll avoid it as much as I can.

Why do you don’t release the HMG IDE source code?
Which are your obscure intentions about it? 

IDE is a very big application. It has about 41000 lines of code.

To make it run faster it relies heavily on MiniGUI library internals and some C code to cover low level things not implemented on the library.

Since it relies on library internals, sometimes, modifications to library, obligate to me to make changes (usually extensive) to IDE code.

IMHO these (and other things) turn this project into a personal one, not suitable to make its code public.

Anyway, I not discard the possibility to make the code public in the future.

I can only assure that IDE will always be FREELY DISTRIBUTED as freeware.

There is no evil intentions behind this decision :)

Maybe there is a problem (not fully specified) with control XXX 
but I’m not sure. Can you fix it please?
My application is not working as expected. I’ve attached to the message all app 5000 lines of code. I guess that must be an HMG problem, please solve it.

Ok. I’ll say once again :)

I cannot analyze a presunct bug based on a tale about it, or read a thousand lines app to attempt to find it. It is very time consuming and inefficient way to go.

Please, send me a simple sample showing the bug, to SourceForge HMG bug tracker. The sample must include all necessary files to compile and run it.

If you are not able to reproduce the problem in a small sample, is highly probable that be not an HMG problem, but a error in your app.

Do you accept donations?

In early 2004, the total suscriptors in all MiniGUI forums was more
than 1500.

I’ve took about three hours a day (sometimes more) to answer all the messages directed to me with help requests.

So, I’ve think that request for donations from the MiniGUI users could be a good idea. It could allow to me, dedicate full time to the project, filling the needs of those using the library to develop professional apps.

Sadly, with the exception of a small group of users, there was no
significant response.

Some time later, I’ve decided to remove donations request from the HMG releases due to the lack of interest from the users.

Based on that experience, I have no plans to do it again.

Regards,

Roberto.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Notes :

1. This article dated to 2008, current address of main HMG site is HMG_Forum and here download page. Also look at “Home page” of HMG for latest announces.

2. This article borrowed courtesy of author from HMG_Forum.

3. Do you like HMG ? If so, don’t forget this !