Harbour for beginners

Alexander Kresin
2003 - 2016

4. Additional libraries

4.1 Overview

Thanks to so-called "Extend system" you can connect the modules written in C, the prgmodule, written in Harbour, which makes it possible to use a large number of different tools programming in C API. Many of these modules are located in the Harbour/contrib, many are available from the manufacturer's site and Open source repositories as so called 3-rd party library. In fact, the significant part of functions, modules of the Harbour is written in C, and uses the same "Extend system".

Below is a list of what is included in the Harbour/contrib at the time of writing this article:

I want to note that not all of these modules are fully ready for use, some are on initial stage.


hbbz2

This library include a set of wrappers for a BZip2 library, it implements a text strings compression / uncompression.

To build programs with hbbz2 you should add bz2 and, of course, hbbz2 itself in your link script.

Functions list:

cCompressed := hb_bz2_Compress( cData, [nDstBufLen|@cBuffer], [@nResult], [nLevel] )Compresses a text string cData, using a compression levelnLevel (0 - 9, 6 by default).
cUnCompressed := hb_bz2_UnCompress( cCompressed, [nDstBufLen|@cBuffer], [@nResul>] )Uncompresses a conpressed text string cCompressed.

hbbz2io

This library implements an I/O driver for BZIP2 compressed streams, it may be used in File IO API functions ( hb_vf*() ) and in transfer RDDs, such as SDF and DELIM.

To build programs with hbbz2io you should add hbbz2, bz2 and, of course, hbbz2io itself in your link script. There must be a following line in a program:

      REQUEST HB_BZ2IO
   

Now, if to write a prefix "bz:" or "bgz[0-9]:" (0 - 9 - demanded compression level) before a file name, bz2io driver will be used, for example:

      REQUEST HB_GZIO, HB_BZ2IO

      FUNCTION GZip2Bz2( cFile )
         RETURN hb_vfCopy( "gz:" + cFile + ".gz", "bz:" + cFile + ".bz2" )

hbgzio

This library implements an I/O driver for GZIP compressed streams, it may be used in File IO API functions ( hb_vf*() ) and in transfer RDDs, such as SDF and DELIM.

To build programs with hbgzio you should add hbzlib and, of course, hbgzio itself in your link script. There must be a following line in a program:

      REQUEST HB_GZIO
   

Now, if to write a prefix "bz:" or "bgz[0-9]:" (0 - 9 - demanded compression level) before a file name, gzio driver will be used, for example:

       REQUEST HB_GZIO

       USE test
       COPY TO gz:test.txt.gz DELIMITED WITH TAB
or
       REQUEST HB_GZIO

       hb_vfCopy( "file.txt", "gz9:file.txt.gz" )
       USE test
       APPEND FROM "gz:file.txt.gz"
       hb_vfErase( "file.txt.gz" )
or
       REQUEST HB_GZIO

       FUNCTION GZIP( cFile )
          RETURN hb_vfCopy( cFile, "gz:" + cFile + ".gz" )

hbmemio

This library implements an I/O driver for files, stored in RAM, it may be used in RDDs and with File IO API functions ( hb_vf*() ).

To build programs with hbmemio you should add hbmemio library in your link script. There must be a following line in a program:

      REQUEST HB_MEMIO

Now, if to write a prefix "mem:" before a file name, memio driver will be used, for example:

       REQUEST HB_MEMIO

       LOCAL i

       dbCreate( "mem:test", { { "F1", "N", 9, 0 } }, , .T., "memarea" )

       FOR i := 1 TO 1000
          dbAppend()
          FIELD->F1 := hb_Random() * 1000000
       NEXT
       INDEX ON FIELD->F1 TAG f1
       dbEval( {|| QOut( FIELD->F1 ) } )
       dbCloseArea()

       /* Copy files to a disk */
       hb_vfCopyFile( "mem:test.dbf", "test1.dbf" )
       hb_vfCopyFile( "mem:test.ntx", "test1.ntx" )

       /* Free memory */
       dbDrop( "mem:test" )

hbmzip

This library includes wrapper functions for MiniZip and some additional functions to provide a higher level API for zip files.

To build programs with hbmzip you should add following libraries in your link script: hbzlib, minizip, and, of course, hbmzip itself.

Most likely, it will be more convenient to use hbziparc library - an API of a more high level :), a superstructure over hbmzip.


hbziparc

This library, based on hbmzip, provides a set of functions for packing / unpacking in zip - format.

To build programs with hbziparc you should add following libraries in your link script: hbzlib, minizip, hbmzip, and, of course, hbziparc itself.

Functions list:

lCompress := hb_ZipFile( cFile, cFileToCompress | aFiles, [nLevel], [bBlock], [lOverWrite], [cPassword], [lWithPath], [lWithDrive], [pFileProgress] )Creates a zip file, returns .T. in case of success.
cFile - a name of the zip file to create,
cFileToCompress | aFiles - a name of a file to Compress, or an array containing files to compress,
nLevel - compression level ranging from 0 (no compression) to 9 (best compression),
bBlock - a code block, which is executed once for each compressed file каждого файла для сжатия, it receives cFile and nPos parameters,
lOverWrite - toggles to overwrite the file if exists,
cPassword - password to encrypt the files,
lWithPath - toggle to store the path or not (.F. by default),
lWithDrive - toggles to store the drive letter or not (.F. by default),
pFileProgress - a codeblock for file progress visualisation, it is something like this: {|nPos,nTotal| GaugeUpdate( aGauge1, nPos / nTotal ) }.
lCompress := hb_UnzipFile( cFile, [bBlock], [lWithPath], [cPassWord], cPath, cFileToExtract | aFile, [pFileProgress] )Unzip a compressed file, returns .T. in case of success.
cFile - a name of the zip file to unpack,
bBlock - a code block, which is executed once for each extracted file каждого файла для сжатия, it receives cFile and nPos parameters,
lWithPath - toggles to create directory if needed,
cPassword - a password to use to extract files,
cPath - a path to extract the files to - mandatory,
cFileToExtract | aFiles - a file or array of files to extract - mandatory,
pFileProgress - a codeblock for file progress visualisation.
lDelete := hb_ZipDeleteFiles( cFile, cFiletoDelete | aFiles | nFilePos )Deletes files from a zip archive, returns .T. in case of success.
cFile - a name of a zip archive,
cFileToExtract | aFiles - a file to be removed or an array of files to be removed.
hb_SetZipComment( cComment )Sets a comment for a zip archive, it should be called before any of the compression function.
cComment := hb_GetZipComment( cFileName )Returns a comment, stored in a zip file.
hb_SetBuffer( [nWriteBuffer], [nExtractBuffer], [nReadBuffer] )Sets the size of the internal buffers for write/extract/read operations. Default values are 65535 / 16384 / 32768 respectively.
lCompress := hb_ZipFileByTDSpan( cFile, cFileToCompress | aFiles, nLevel, bBlock, lOverWrite, cPassword, iSize, lWithPath, lWithDrive, pFileProgress)Creates a zip file, divided to few parts, returns .T. in case of success.
The parameters are the same as in hb_ZipFile() and, additionally:
iSize - a size n bytes, 1457664 by default.
lCompress := hb_ZipFileByPKSpan( cFile, cFileToCompress | aFiles, nLevel, bBlock, lOverWrite, cPassword, lWithPath, lWithDrive, pFileProgress )Creates a zip file on removable media, returns .T. in case of success.
nReturnCode := hb_ZipTestPK( cFileName )Test pkSpanned zip files, return code is:
        114   Incorrect Disk
        103   No Call back was set with hb_ZipTestPK()
        
hb_SetDiskZip( bBlock ) 
nFiles := hb_GetFileCount( cFileName )Returns a number of files in a zip archive, including directories.
hb_GetFilesInZip( cFileName [, lVerbose] )Returns an array with an information about files in a zip archive.
If lVerbose is not passed, or it is .F., this is a one dimensional array with files names, if it is .T. - a two dimensional array with the following info for every file: { cFileName, nSize, nMethod, nCompSize, nRatio, dDate, cTime, hb_NumToHex( nCRC, 8 ), nInternalAttr, lCrypted, cComment }

4.2 GUI

Harbour in "pure" provides a means to create console programs; to implement graphical user interface ( GUI ) it is necessary to use additional libraries. Below are listed the most used.



Comments:       ()       prev.    next.       Add comment
The length of a comment - no more than 4000 characters.
Your name:

Email address:
(not be shown publicly)
 
Input text from an image: