Ejemplo de Harbour usando ADO

Descarga el código y la base de datos .MDB aquí

/*
* http://www.mig2soft.com
* “tbrowADO.prg” Ejemplo de Tbrowse y ADO
* (c) MigSoft 2008 <fugaz_cl/at/mig2soft.com>
*/

#include “ado.ch”
#include “TBrowse.ch”

#ifndef __XHARBOUR__

ANNOUNCE HB_GTSYS
REQUEST HB_GT_WIN

#endif

Function Main()

setmode(25,80)
clear

/********** Cadena de Conexion **********/

cCad := “Provider=Microsoft.Jet.OLEDB.4.0;” + ;
“Data Source=Agenda.mdb”

/************ Abrir Conexion ************/


oMiConexion := CreateObject(“ADODB.Connection”)
oMiConexion:
Open(cCad)
oRecordSet :
= CreateObject(“ADODB.recordset”)

oRecordSet:LockType   := adLockOptimistic
oRecordSet:CursorType :
= adOpenKeyset
oRecordSet:ActiveConnection(oMiconexion)
oRecordSet:Source :
= “Select * from contactos”
oRecordSet:Open()
oRecordSet:MoveFirst()

/************ Crear TBrowse ************/

oBrw := TBrowseNew(0,0,24,79)
oBrw:headSep   :
= “-“
oBrw:colorSpec := “N/BG,W+/R”

oBrw:goBottomBlock := {|| oRecordSet:MoveLast()}
oBrw:goTopBlock :
= {|| oRecordSet:MoveFirst()}

oBrw:SkipBlock := {|nSkip| RecordSetSkip(nSkip)}

oBrw:AddColumn(TBColumnNew(“Apellido”,;
{|| oRecordSet:Fields(“apellido”):value}))
oBrw:AddColumn(TBColumnNew(
“Nombres”,;
{|| oRecordSet:Fields(“nombres”):value}))
oBrw:AddColumn(TBColumnNew(
“Direccion”,;
{|| oRecordSet:Fields(“calle”):value}))

/************ Display TBrowse ************/

DO WHILE .T

oBrw:forceStable()

nKey := Inkey(0)
IF oBrw:applyKey( nKey ) == TBR_EXIT
EXIT
ENDIF

ENDDO

/************ Cerrar Conexion ************/

oMiConexion:Close()

clear

Return(Nil)

Static Function RecordSetSkip(nSkip)

LOCAL nRec := oRecordSet:AbsolutePosition
oRecordSet:Move(nSkip)
IF oRecordSet:EOF; oRecordSet:MoveLast(); ENDIF
IF oRecordSet:BOF; oRecordSet:MoveFirst(); ENDIF

Return(oRecordSet:AbsolutePosition-nRec)



Proyecto de “Desarrollo de Software”

  1. La solicitud del usuario
  2. Lo que entendió el líder del proyecto
  3. El diseño del analista de sistemas
  4. El enfoque del programador
  5. Las recomendaciones del consultor externo
  6. La documentación del proyecto
  7. La implantación en producción
  8. El presupuesto del proyecto
  9. El soporte operativo
  10. Lo que el usuario realmente necesita

El Proceso se indica en la siguiente imagen (Fuente:  Objeto Persistente )

Mundo Sourceforge

No hay duda de la gran importancia que tiene para muchos desarrolladores la palabra Sourceforge, allí nacen cada día excelentes proyectos, bajo la categoría de software libre.

Trataré de divulgar el resultado de algunos proyectos que me a tocado instalar y probar.

Andaba buscando un software con funciones parecidas al conocido shareware Total Commander para Windows, utilizado para la gestión de archivos, ficheros, carpetas, folders, etc.

Encontré el proyecto llamado muCommander, que se acerca a lo que se necesita, me llamó la atención porque es multiplataforma y tiene versiones actualizadas.

Para aquellos que como yo trabajan con temas contables les presento el proyecto Gazie, escrito con PHP usando base de datos MySQL.

Para instalar Gazie se necesita previamente XAMPP u otra distribución que instale Apache, MySQL y PHP.

Herramientas infaltables en Linux

Habilitar todos los repositorios de Ubuntu,

Sistema/Administración/Gestor de paquetes Synaptic

Configuración/Repositorios -> Habilitar todos los repositorios

  • Equivalente Linux de Norton Commander para navegar entre los archivos en modo texto contamos con Midnight Commander es decir funciona en consola.

sudo -s

apt-get install mc

mc

  • Equivalente Linux de Total Commander para explorar archivos en modo gráfico, existe Gnome Commander.

sudo -s

apt-get install gnome-commander

Aplicaciones/Accesorios/GNOME Commander

También son recomendables Abiword equivalente a Word y Gnumeric equivalente a Excel.

gFTP un excelente cliente FTP, QTParted para gestión de particiones de disco duro.

Aplicaciones/Añadir y quitar…

Como compilar en Harbour

/*

* $Id: howtobld.txt 9191 2008-08-19 13:11:22Z vszakats $

*/

In the last phase of install process if bash shell is available in the

system then few bash scripts are created to make compiling and linking

with Harbour a little easier. There are compiler and linker wrappers

called “hbcc“, “hbcmp“, “hblnk” and “hbmk“.

hbcc” is a wrapper to the C compiler only. It sets all flags

and paths necessary to compile .c files which include Harbour header

files. The result of its work is an object file.

Use “hbcmp” exactly as you would use the harbour compiler itself.

The main difference with hbcmp is that it results in an object file,

not a C file that needs compiling down to an object. hbcmp also

ensures that the harbour include directory is seen by the harbour compiler.

hblnk” simply takes a list of object files and links them together

with the harbour virtual machine and run-time library to produce an

executable. The executable will be given the basename of the first object

file if not directly set by the “-o” command line switch.

hbmk” tries to produce an executable from your .prg file. It’s a simple

equivalent of cl.bat from the CA-Clipper distribution.

All these scripts accept command line switches:

-o<outputfilename>    # output file name

-static                          # link with static Harbour libs

-fullstatic                     # link with all static libs

-shared                        # link with shared libs (default)

-mt                              # link with multi-thread libs

-gt<hbgt>                   # link with <hbgt> GT driver, can be repeated to

# link with more GTs. The first one will be

# the default at runtime

-xbgtk                          # link with xbgtk library (xBase GTK+ interface)

-hwgui                          # link with HWGUI library (GTK+ interface)

-l<libname>                 # link with <libname> library

-L<libpath>                  # additional path to search for libraries

-fmstat                         # link with the memory statistics lib

-nofmstat                     # do not link with the memory statistics lib (default)

-[no]strip                      # strip (no strip) binaries

-main=<main_func>     # set the name of main program function/procedure.

# if not set then ‘MAIN’ is used or if it doesn’t

# exist the name of first public function/procedure

# in first linked object module (link)

Link options work only with “hblnk” and “hbmk” and have no effect

in “hbcc” and “hbcmp“.

Other options are passed to Harbour/C compiler/linker.

An example compile/link session looks like:

[email protected]:~/tmp$ cat foo.prg

function main()

? “Hello, World!”

return nil

[email protected]:~/tmp$ hbcmp foo

Harbour Compiler Alpha build 46.2 (Flex)

Copyright 1999-2006, http://www.harbour-project.org/

Compiling ‘foo.prg’…

Lines 5, Functions/Procedures 2

Generating C source output to ‘foo.c’… Done.

dru[email protected]:~/tmp$ hblnk foo.o

[email protected]:~/tmp$ strip foo

[email protected]:~/tmp$ ls -l foo

-rwxrwxr-x    1 druzus   druzus       3824 maj 17 02:46 foo

or using hbmk only:

[email protected]:~/tmp$ cat foo.prg

function main()

? “Hello, World!”

return nil

[email protected]:~/tmp$ hbmk foo

Harbour Compiler Alpha build 46.2 (Flex)

Copyright 1999-2006, http://www.harbour-project.org/

Compiling ‘foo.prg’…

Lines 5, Functions/Procedures 2

Generating C source output to ‘foo.c’… Done.

[email protected]:~/tmp$ ls -l foo

-rwxrwxr-x    1 druzus   druzus       3824 maj 17 02:46 foo

You will find additional wonderful tools: /usr/bin/hbrun

You can run clipper/xbase compatible source files with it

if you only put in their first line:

#!/usr/bin/hbrun

For example:

[email protected]:~/tmp$ cat foo.prg

#!/usr/bin/hbrun

function main()

? “Hello, World!, This is a script !!! “

?

return nil

[email protected]:~/tmp$ chmod +x foo.prg

[email protected]:~/tmp$ ./foo.prg

Hello, World!, This is a script !!!

[email protected]:~/tmp$

I hope you will find this information useful,

Przemyslaw Czerpak (druzus/at/priv.onet.pl)

A propósito de GT driver

How to create such base GUI GT driver?

See as example GTGUI in source/rtl/gtgui/gtgui.c

It supports only TONE and CLIPBOARD operations.

GUI libraries can use it or create other GT driver inheriting from

this one.

NOTE: source/rtl/gtgui/gtdef.c is a hack which overloads the default

Harbour build time GT driver and should not be replicated.

  • gtnul – base GT driver from which each other inherits.

it gives screen buffer functionality but does not

produce any screen output from disp*() commands

Only outStd()/outErr() are supported.

It’s present on all platforms and i always linked.

  • gtcgi – very simple GT driver which does not make any output

formatting and simply send it as to stdout.

Supported by all platforms.

  • gtstd – it uses stdout output but tries to support full screen output but

without collor support and cursor shape. It format text to number

of row and columns if is able to detect these values on given

platform.

Supported by all platforms.

  • gtpca – It’s PCANSI terminal GT – it works in similar way to ANSI GT

driver in Clipper though keyboard input is not fully supported.

Now GTTRM can make all GTPCA job and much more.

Supported by all platforms.

  • gtdos – GT driver for DOS – it uses BIOS and direct hardware screen output

so it’s very similar to Clipper one – in practice due to the same

environment you will noticed that all small details of Clipper

GT drivers are replicated here. You can think about it like 100%

Clipper compatible.

Supported only by DOS builds.

  • gtos2 – GT driver for OS2 – It’s sth like GTWIN but for other OS.

Supported only by OS2 builds.

  • gtwin – GT driver for MS-Windows console window.

Supported only by MS-WINDOWS (W95 or higher) builds.

  • gtcrs – GT driver for platforms which supports curses or compatible

(ncurses) library – in practice POSIX systems.

Supported by POSIX systems (mostly different *nixes)

  • gtsln – GT driver for platforms which supports slang library.

It’s like GTCRS but instead of CURSES it uses SLANG.

Supported by POSIX systems (mostly different *nixes).

It supports Unicode input/output if compiled with slang

version which also supports it.

  • gttrm – it’s like GTCRS and GTSLN but it does not use any external

terminal library like SLANG or CURSES and it does not use

any external database to extract terminal capabilities so

it can be compiled on any POSIX system – I’ll add support

also for DOS/Windows in the future. It should automatically

detect UTF-8 terminal mode and switch internally to Unicode

mode if necessary. In theory is less functional then GTCRS

and GTSLN because I hard coded escape sequences only for few

terminals but because I added support also for some non

standard terminal extensions and I’m using very limited set

of output sequences then it usually works better then GTCRS

and GTSLN.

Supported by POSIX systems (mostly different *nixes)

  • gtwvt – GT driver for MS-Windows. It creates its own GUI window

instead of using MS-console window. It allows to change

font, window size, etc.

Supported only by MS-WINDOWS (W95 or higher) builds.

is a pure console implementation of traditional Clipper terminal

taking Windows API as its base console IO protocols. Its OI are

rendered in a Windows window and hence all of MSDN is available

for use with GTWVT.

To let the memory refreshed, I must remind

everybody that it is a superb work of Peter Rees contributed

to xHarbour on 22nd December 2003.

  • GTWVG – GUI emulation of GTWVT. It implements itself on top of GTWVT.

GTWVG ( WVTGUI in xHarbour ) offers functions and classes to

present a console application look like a windows one.

It renderes GUI elements on top of Clipper elements

( GETS, BROWSERS, BOXES, LINES ) which makes them

feel like a Windows element. GTWVG can be used with existing

code just adding some more code but without sacrificing or

modifying old one.

Also all IO commands can be rendered on top of the GUI elements

  • gtxwc – GT driver for X-Window. It’s like GTWVT but for nixes.

Additionaly it has set of predefined vector characters

(box and arrowd drawing characters) which can be used

instead of the one defined in font. It means that you

will have all boxes and arrows you know from DOS ans CP437

even if you chose font which does not have them. Additionally

it support some simple graphic output. See tests/gfx.prg

for simple program which demonstrates it.

Supported by POSIX systems (mostly different *nixes)

  • gtalleg– GT driver which uses alegro library for input/output.

It’s also GUI driver which support HB_GFX*() drawing.

Multi platform, works on all platforms for which allegro

library has been ported: MS-Win, DOS, VESA, X11, FB, SDL, …

  • gtgui – pseudo GT driver which adds to GTNUL Clipboard and Tone

functionality. If you are using some MS-Windows GUI library

and you still want to use TONE() function or GTI_CLIPBOARD

actions then link this GT driver with your application.

If you do not want to use TONE() or GTI_CLIPBOARD then

do not link it – it will be only waste of memory.

  • gtctw – GT driver which adds CT3 Window functionality to any other

GT driver from which it inherits. It’s activated automatically

when you execute first W*() function.

In similar way in Harbour it’s possible to add support for

GTWVW inheriting from GTWVT.

Some of the GT drivers support additional functionality with hb_gtInfo()

interface.

See include/hbgtinfo.ch for different actions.

Best regards,

Przemek

Controlando la consola

How to get rid of unwanted console in Windows GUI applications

By Przemyslaw Czerpak (druzus/at/priv.onet.pl)

Do not use GTWIN 🙂

GTWIN is a driver for users who wants to write GUI applications and

should give them all possible features. GUI libraries do not have to

use GT drivers if they don’t need any GT functionality, or if they

don’t want to give users support for standard Clipper/Harbour functions

which operate on GT resources.

Harbour application can work without any GT driver. In such case all

functions which operates on GT resources are redirected to meta GT

driver (GTNUL) which is part of RTL library. This driver makes all

operations on memory buffer and only OUTSTD()/OUTERR() output is sent

outside. All GT drivers inherits from GTNUL or from other GTs but in

the inheritance chain the first GT driver is always GTNUL.

Because there is no hard coded bindings between core code and other GT

drivers, then by default only GTNUL will be linked. So if you will want

to use some real GT you will have to add to your code:

REQUEST HB_GT_<name>

Setting the default GT driver is done exactly the same as setting the

default RDD. In RDD it request DBFNTX by default. It is done inside a

module with RDDSYS() symbol, and core code contains:

REQUEST RDDSYS

Something like that is also done by Clipper. If you add to your code

RDDSYS symbol, then the default RDD will not be linked because your

RDDSYS will overload the default one (of course if it will be linked

before the one in core code). So it’s enough to write something like:

ANNOUNCE RDDSYS

or:

PROC RDDSYS; RETURN

Both gives the same effect, and default RDD (DBFNTX) will not be linked.

Exactly the same I’ve done in GT subsystem. HB_GTSYS() makes exactly

the same job as RDDSYS() but for GT. This symbol is requested by core

code and in the module where it is defined it request default build GT

driver or if it’s not set then default GT driver for given platform.

For Windows it looks like:

ANNOUNCE HB_GTSYS

REQUEST HB_GT_WIN

This causes that normal console applications do not have to explicitly

request GT driver and the one set in the module with HB_GTSYS is always

linked. If you do not want to link the GT driver then you have to make

the same as for RDD and add to your code:

ANNOUNCE HB_GTSYS

or:

PROC HB_GTSYS; RETURN

In such case your final application will not have any GT driver. If you

want to use GTNUL as base, you should add:

REQUEST HB_GT_NUL

Though IMHO this request should be part of GUI library core code. You

can link with your application more then one GT driver. It’s enough

that you add more lines with:

REQUEST HB_GT_<name>

For example, compile this code:

/*** t.prg ***/

REQUEST HB_GT_WIN

REQUEST HB_GT_WVT

PROCEDURE MAIN()

? HB_GTVERSION(), HB_GTVERSION(1)

TONE( 200, 3 )

TONE( 300, 3 )

TONE( 500, 3 )

INKEY( 0 )

RETURN

and link it as Windows GUI application. Then simply execute:

t //GTWIN

and:

t //GTWVT

Most of Windows linkers execute startup initialization code in the

order of linked modules, so the first linked GT driver will be the

default one. But you can control it also from your application, by

requesting HB_GT_<name>_DEFAULT symbol (I do not like this name because

it cannot be used with 10 character symbols so I’m ready for any other

positions). For example, if you add to your code:

REQUEST HB_GT_NUL_DEFAULT

Then GTNUL will be the default GT driver, and even if you would not

disable GTWIN and link it with your application, GTWIN will not be

activated but GTNUL.

It could be intentional, because if your application is linked with more

GTs, then you can also set the default one when you start your

application using //GT<name> switch, or HB_GT environment variable. So

you can create GUI application which will set the default GT driver to

NUL and will not activate GTWIN, and when you’ll want to enable debug

messages, you simply run:

myprog //GTWIN

and debug messages will use the GTWIN console window. You can think of

other situations when it could be useful to have full functional GT

driver in GUI application. You can even create mixed GUI/CUI code in one

program.

And finally, the TONE() function problem.

Low level TONE code is part of GT driver. In the past, GUI libraries in

Windows were linked the whole GTWIN driver and only TONE were used. It

was possible because someone blocked GTWIN to work with application

linked as Windows GUI programs. Now, GTWIN can be used with any

applications, and I do not want reduce its functionality. So GUI

libraries which needs TONE should have their own GT driver which will

support it. Now, such GT driver can also give much more features for

final users, because it allow to integrate GUI library with standard

Clipper screen functions.

Notas respecto a Linux

/*
* $Id: linux1st.txt 9918 2008-11-12 19:03:30Z vszakats $
*/

Linux primer

Ubuntu/Debian distro
——————–

Packages needed to cleanly build Harbour:
(Tested with Ubuntu 7.04 and 8.04)

For GTCRS terminal lib:
sudo apt-get install libncurses-dev

For GTSLN terminal lib:
sudo apt-get install libslang2-dev

For GTXWC terminal lib:
sudo apt-get install libx11-dev

For console mouse support in GTTRM, GTSLN and GTCRS:
sudo apt-get install libgpmg1-dev

For contrib/hbodbc lib:
sudo apt-get install unixodbc-dev

For contrib/hbcurl lib:
sudo apt-get install libcurl4-openssl-dev
or
sudo apt-get install libcurl4-gnutls-dev

For contrib/hbfbird lib:
sudo apt-get install libfirebird2.0-dev
or
sudo apt-get install firebird2.1-dev

For contrib/hbfimage lib:
sudo apt-get install libfreeimage-dev

For contrib/hbgd lib:
sudo apt-get install libgd2-xpm-dev
or
sudo apt-get install libgd-xpm-dev

For contrib/hbmysql lib:
sudo apt-get install libmysqlclient15-dev

For contrib/hbpgsql lib:
sudo apt-get install libpq-dev

For contrib/hbgf/hbgfgtk lib:
sudo apt-get install libgtk2.0-dev
sudo apt-get install libglib2.0-dev

For contrib/rddads lib:
Download and install ‘Advantage Client Engine API for Linux’ package
(f.e. aceapi-9.00.0.0.tar.gz)

For contrib/hbhpdf lib:
Download and ‘./configure’, ‘make install’ libharu
from http://libharu.org/

openSUSE distro

You’ll need these packages to compile certain contribs and optional
Harbour modules:

– xorg-x11-devel
– postgresql-devel
– gtk2-devel
– ncurses-devel
– slang-devel
– unixodbc-devel
– gd-devel
– libmysqlclient-devel

For contrib/rddads lib:
Download and install ‘Advantage Client Engine API for Linux’ package
(f.e. aceapi-9.00.0.0.tar.gz)

For contrib/libharu:
– Download and ‘./configure’, ‘make install’ libharu
from http://libharu.org/
– libpng-devel
– zlib-devel

Primer programa en Linux

/*
* http://www.mig2soft.com
* “hola.prg” Ejemplo básico Harbour para Linux
* Copyright 2008 MigSoft <fugaz_cl/at/mig2soft.com>
*/
ANNOUNCE HB_GTSYS
REQUEST HB_GT_STD_DEFAULT
PROCEDURE Main()
CLS
@ 0,0 SAY “Hola Mundo”
Inkey(0)
RETURN
En consola:
sudo -s
hbmk -static hola
./hola

Script para compilar en Linux

sudo -s

gedit bld.sh

Copiamos y pegamos lo siguiente :

#!/bin/sh

if [ -z “$HB_PREF” ]; then export HB_PREF=hb; fi
if [ -z “$HB_ARCHITECTURE” ]; then export HB_ARCHITECTURE=w32; fi
if [ -z “$HB_GPM_MOUSE” ]; then export HB_GPM_MOUSE=no; fi
if [ -z “$HB_COMPILER” ]; then export HB_COMPILER=mingw32; fi
if [ -z “$HB_GT_LIB” ]; then export HB_GT_LIB=gtwin; fi
if [ -z “$HB_BIN_INSTALL” ]; then export HB_BIN_INSTALL=/harbour/bin/; fi
if [ -z “$HB_LIB_INSTALL” ]; then export HB_LIB_INSTALL=/harbour/lib/; fi
if [ -z “$HB_INC_INSTALL” ]; then export HB_INC_INSTALL=/harbour/include/; fi

LIBFILES=”-Wl,–start-group “

LIBFILES=”$LIBFILES -lhbdebug -lhbvm -lhbrtl -lhbrdd -lhbrtl -lhbvm

-lhbmacro -lhbpp -lhblang -lhbcpage -lhbcommon -lrddntx -lrddcdx

-lrddfpt -lhbsix -lhbhsx “

if [ $HB_COMPILER = mingw32 ]; then
LIBFILES=”$LIBFILES -lgtwin -lgtgui “
fi

if [ $HB_GT_LIB = gtcrs ]; then
LIBFILES=”$LIBFILES -lgtcrs -lncurses “
fi

if [ $HB_GT_LIB = gtsln ]; then
LIBFILES=”$LIBFILES -lgtsln -lslang “
fi

LIBFILES=”$LIBFILES -Wl,–end-group “

if [ $HB_COMPILER = mingw32 ]; then
CFLAGS=”-W -Wall -O2 -mms-bitfields -mwindows -mno-cygwin “
LIBFILES=”$LIBFILES -lm -luser32 -lwinspool -lole32 -loleaut32

-luuid -lgdi32 -lcomctl32 -lcomdlg32 -lodbc32 -lwininet -lwsock32″
else
CFLAGS=”-W -Wall -O2″
fi

$HB_BIN_INSTALL/harbour -b -a -m -n -w -I$HB_INC_INSTALL $1

gcc $1.c -o $1 $CFLAGS -L$HB_LIB_INSTALL

-I$HB_INC_INSTALL $LIBFILES `pkg-config –cflags gtk+-2.0`

`pkg-config –libs gtk+-2.0 libglade-2.0`

rm -f $1.c
rm -f $1.o

./$1

Guardamos como bld.sh

en consola escribimos

chmod +x bld.sh

para compilar nuestro ejemplo

./bld.sh hola

en Linux | 253 Palabras