string to parameter

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: string to parameter

Post by PeteWG »

Hi,

Try this:

Code: Select all

LOCAL aColors, cColor

   // fill this hash array with all color pairs you'd possibly need)
   aColors := { "WHITE"=>WHITE, "GRAY"=>GRAY, "RED"=>RED, "GREEN"=>GREEN } 
   cColor := "RED"
   @ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR hb_HGetDef( aColors, cColor, BLACK )  CENTER 
   cColor := "GREEN"
   @ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR hb_HGetDef( aColors, cColor, BLACK )  CENTER
it will work. (it's used in production-code for years)

regards,
Pete
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: string to parameter

Post by andyglezl »

Gracias Pete, es bueno saberlo para cuando tengamos la necesidad de usarlo.
--------------------------------------------------------------------
Thanks Pete, it's good to know when we need to use it.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: string to parameter

Post by andyglezl »

Me intrigo eso de poder convertir definiciones en variables y empeze a hacer esto...
Pero "ya me trabe" con el manejo de los arrays.

Alguien lo quiere seguir ?
----------------------------------------------------------------------------------------------------------
I am intrigued by being able to convert definitions into variables and I started doing this ...
But "I'm stuck" with the management of the arrays.

Does someone want to follow him?

Code: Select all

#include "hmg.ch"  

FUNCTION Main()
	DEFINE WINDOW Form_1 AT 100,500 WIDTH 500 HEIGHT 200 TITLE "TEST" MAIN ON INIT Convert(  )
		@ 010 , 010 LABEL Label_01  WIDTH 400 VALUE "#DEFINE 2 PUBLIC VARIABLE" FONT "Arial" SIZE 20 BOLD
	END WINDOW
	Form_1.Activate 
RETURN
*---------------------------------*
Function Convert(  )
//  THIS, IS IN MI CASE !!!
cColors := Memoread("D:\AGL\HMG\3.4.4\INCLUDE\i_color.ch" )
cColors := StrTran( cColors, "{", '",{' )
cColors := StrTran( cColors, "#define ", '{"' )
cColors := StrTran( cColors, "}", '} },' )
cColors := StrTran( cColors, CHR(9), "" )
cColors := "{ " + cColors + " }"

// hb_ATokens( <cString>, [<cDelim>|<lEOL>], [<lSkipStrings>], [<lDoubleQuoteOnly>] )
aTokens := hb_ATokens( cColors )		;	msgbox( ValType( aTokens ) )	;	msgbox( aTokens )
For i1 = 1 TO LEN( aTokens )
	__mvPublic( aTokens[ i1, 1 ] )
	__mvPut( aTokens[ i1, 1 ], aTokens[ i1, 2 ] )
NEXT
Return .T.
*---------------------------------*
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: string to parameter

Post by srvet_claudio »

Try with Harbour preprocesor functions:

pPP := __pp_Init ( "C:\HMG.3.4.4\INCLUDE" , "HMG.CH" ) // Init Harbour PreProcesor

aColor := __pp_Process ( pPP, "BLACK" ) // Run Harbour PreProcesor
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: string to parameter

Post by andyglezl »

Entonces, volviendo al problema de jairpinho.
Lo siguiente debería de funcionarle.
-----------------------------------------------------------
Then, returning to the problem of jairpinho.
The following should work for you.

pPP := __pp_Init ( "D:\HMG\3.4.4\INCLUDE" , "HMG.CH" ) // Init Harbour PreProcesor
// aColor := __pp_Process ( pPP, oRow: fieldGet (28) )
aColor := __pp_Process ( pPP, "RED" ) // Run Harbour PreProcesor
@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR &aColor CENTER // -> it should work


Gracias Dr. Claudio !!!
Andrés González López
Desde Guadalajara, Jalisco. México.
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: string to parameter

Post by PeteWG »

srvet_claudio wrote: Sat Oct 27, 2018 6:43 pm Try with Harbour preprocesor functions:

pPP := __pp_Init ( "C:\HMG.3.4.4\INCLUDE" , "HMG.CH" ) // Init Harbour PreProcesor

aColor := __pp_Process ( pPP, "BLACK" ) // Run Harbour PreProcesor
this is, probably, the comment of the month! ;-)
--or at least, the most intriguing hint, regarding the preprocessor
and the mystic internals of 'harbour compiler'.
thanks for posting!

regards,
Pete
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: string to parameter

Post by jairpinho »

Thank you guys, I'll test.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: string to parameter

Post by SALINETAS24 »

Hola.., has probado esto..? ;)

Code: Select all

Local cColor := { 255, 0, 0}
@ 84, 275 HPDFPRINT "R$ TOTAL" FONT cFonte1 size nFonte_size1 COLOR cColor CENTER  //  -> does not work
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
Post Reply