string to parameter

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

PeteWG
Posts: 126
Joined: Sun Mar 21, 2010 5:45 pm
Has thanked: 6 times
Been thanked: 36 times

Re: string to parameter

Post by PeteWG » Thu Oct 25, 2018 7:11 am

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: 1028
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » Thu Oct 25, 2018 2:02 pm

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: 1028
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » Sat Oct 27, 2018 4:51 am

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: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 146 times
Contact:

Post by srvet_claudio » 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
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
andyglezl
Posts: 1028
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 21 times
Been thanked: 42 times
Contact:

Post by andyglezl » Sat Oct 27, 2018 7:31 pm

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: 126
Joined: Sun Mar 21, 2010 5:45 pm
Has thanked: 6 times
Been thanked: 36 times

Post by PeteWG » Sun Oct 28, 2018 12:11 pm

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: 236
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 2 times
Contact:

Post by jairpinho » Mon Oct 29, 2018 9:21 pm

Thank you guys, I'll test.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

Post Reply