Page 1 of 2

HRB V/S LIB

Posted: Wed Apr 12, 2017 7:14 pm
by luisvasquezcl
Estimados, retomando una inquietud que tuvo Vanguarda, me puse a investigar un poco con los archivos .hrb (mis agradecimientos a Fernando Chirico por la pista ) y me encuentro que son muy útiles a la hora de actualizar nuestros programas sin tener que enviar el ejecutable sino sólo las rutinas que fueron modificadas.
Para eso podemos usar los archivos .hrb en donde podremos generar todo el código necesario para que funcione nuestra aplicación.
Les dejo un ejemplo muy simple de como usar esta utilidad.
Como compilar el ejemplo

- Para generar el archivo .hrb
harbour.exe libreria.prg /gh

- Para compilar el ejecutable.

c:\hmg.3.4.3\build.bat test5.prg

espero les sea de utilidad o por lo menos para salir de curiosidad.
Saludos cordiales,
Luis Vasquez.
test5.zip
(734 Bytes) Downloaded 362 times
I use hmg3.4.3, please modify .bat files for your hmg version

Dear friends, returning to a concern that Vanguarda had, I started to investigate a bit with .hrb files (my thanks to Fernando Chirico for the track) and I find they are very useful when updating our programs without having to send the executable But only the routines that were modified.
For that we can use .hrb files where we can generate all the necessary code for our application to work.
I leave a very simple example of how to use this utility.
How to compile the example

- To generate the .hrb file
Harbour.exe libreria.prg / gh

- To compile the executable.

C: \ hmg.3.4.3 \ build.bat test5.prg

I hope it is useful or at least to get out of curiosity.
Best regards,
Luis Vasquez
test5.zip
(734 Bytes) Downloaded 362 times

Re: HRB V/S LIB

Posted: Wed Apr 12, 2017 8:46 pm
by Pablo César
Interesante. Gracias por compartir, Luis.

Re: HRB V/S LIB

Posted: Wed Apr 12, 2017 10:59 pm
by hmgaams57
Thanks for sharing. Said

Re: HRB V/S LIB

Posted: Thu Apr 13, 2017 6:51 am
by serge_girard
Thanks Luis !

The commands however should be:

BUILDEXE TEST5.PRG
BUILDHRB LIBRERIA.PRG

Serge

Re: HRB V/S LIB

Posted: Thu Apr 13, 2017 7:20 am
by mol
Interesting!

Re: HRB V/S LIB

Posted: Thu Apr 13, 2017 7:58 am
by serge_girard
Actually this means that we can stuff libreria.prg with all kinds of UDF and call them from any PRG as long as libreria.hrb is present somewhere.
Sounds very usefull. Once program test5 is compiled you can modify/upgrade libreria.prg/hrb.

Serge

Re: HRB V/S LIB

Posted: Thu Apr 13, 2017 10:12 am
by gfilatov
serge_girard wrote: Thu Apr 13, 2017 7:58 am Actually this means that we can stuff libreria.prg with all kinds of UDF and call them from any PRG as long as libreria.hrb is present somewhere.
Sounds very usefull. Once program test5 is compiled you can modify/upgrade libreria.prg/hrb.
Hello Serge,

Please note that we can generate an encrypted HRB file at runtime also.

Take a look for the following sample from the MiniguiEx distribution:

Code: Select all

#include "hmg.ch"

PROCEDURE Main

   DEFINE WINDOW Win_Main ;
	AT 0,0 ;
	WIDTH 600 ;
	HEIGHT 400 ;
	TITLE 'Harbour Script Usage Demo' ;
	MAIN ;
	FONT 'Times New Roman' SIZE 12

	DEFINE STATUSBAR ;
		FONT 'Times New Roman' SIZE 12
		STATUSITEM ''
	END STATUSBAR

	@10,10 BUTTON Btn_1 ;
		CAPTION 'Run Script' ;
		WIDTH 200 ;
		HEIGHT 25 ;
		ONCLICK RunScript()

   END WINDOW

   Win_Main.StatusBar.Item(1) := 'HMG Power Ready'

   CENTER WINDOW Win_Main
   ACTIVATE WINDOW Win_Main

RETURN


PROCEDURE RunScript

   LOCAL cCONTENT, hHANDLE_HRB, cPRG, cHRBCODE
   LOCAL cFILE := "script.hrb", cPASSWORD := "MyPasswordKey"

   IF !FILE( cFILE )

      cPRG := ;
         "proc p()" + hb_eol() + ;
         "   SetProperty ( 'Win_Main', 'StatusBar' , 'Item' , 1 , 'Hello World!' ) " + hb_eol() + ;
         "   MsgInfo( 'Hello World!' )" + hb_eol() + ;
         "return"

      cHRBCODE := hb_compileFromBuf( cPRG, "harbour", "-n", "-w3", "-es2", "-q0" )

      MEMOWRIT( cFILE, sx_encrypt( cHRBCODE, cPASSWORD ) )

   ENDIF

   cCONTENT := sx_decrypt( MEMOREAD( cFILE ), cPASSWORD )

   hHANDLE_HRB := hb_hrbload( cCONTENT )

   hb_hrbDo( hHANDLE_HRB )

   hb_hrbunload( hHANDLE_HRB )

RETURN
Hope that useful :idea:

Re: HRB V/S LIB

Posted: Thu Apr 13, 2017 10:23 am
by Anand
Very good example of using scripts in HMG, thanks luisvasquezcl and gfilatov
Now we can add features to existing exe quickly and sent to client.

Regards,

Anand

Re: HRB V/S LIB

Posted: Thu Apr 13, 2017 10:53 am
by serge_girard
Thanks Grigory ! Very interesting subject with much possibilities to discover!

Serge

Re: HRB V/S LIB

Posted: Thu Apr 13, 2017 2:43 pm
by luisvasquezcl
Hola estimados, gracias por sus palabras. Cuando vi las posibilidades que nos ofrece el uso de los archivos .hrb como libreria me interesó mucho ya que tengo un programa que se debe actualizar cada cierto tiempo por temas legales y hay que ir a instalar el nuevo ejecutable por cada actualización y no es muy divertido.
Dejo abierto el tema para su investigación, aportes, comentarios y críticas por supuesto.
un saludos desde chile,
Luis Vasquez.

Hello dear, thank you for your words. When I saw the possibilities offered by the use of .hrb files as a library I was very interested because I have a program that must be updated from time to time by legal issues and you have to go install the new executable for each update and it is not very funny.
I leave the topic open for your research, input, comments and criticisms of course.
A greetings from chile,
Luis Vasquez.