HMG4 - anybody know how to make a dynamic menu ?

Moderator: Rathinagiri

Post Reply
ClaudioGalera
Posts: 47
Joined: Tue Jul 14, 2009 1:14 pm
Location: Mar del Plata, Argentina

HMG4 - anybody know how to make a dynamic menu ?

Post by ClaudioGalera »

Hi ! :)
I need make a main menu dinamic from file dbf in HMG4.Like as menudbf from Minigui (\minigui\samples\basic\menudbf) - I try compile this example but it make error :(

Thank you

Claudio Galera

(Ignore the error defined by the window, please)
MenuDBF.zip
(12.17 KiB) Downloaded 504 times
User avatar
danielmaximiliano
Posts: 2607
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: HMG4 - anybody know how to make a dynamic menu ?

Post by danielmaximiliano »

Hola Claudio:
ya quedo el codigo sin errores para HMG.0.3.40

Code: Select all

#include 'hmg.ch'
#include 'common.ch'
#define CrLf       chr(13)+chr(10)
#define cAcercaDe  "Ejemplo de definición de menú"+CrLf+"en tiempo de ejecución"+CrLf+CrLf+cVersion+CrLf+CrLf+chr(174)+" Abril 2006, Roberto Sánchez"+CrLf+CrLf+MiniGUIVersion()+CrLf+Version()
#define cFaltaMenu "Falta la tabla MenuDBF.DBF","Falta Archivo"
#define cVersion   "Versión 00.00.01"

Static aListItens:={}

Function Main()
	Public cm_tipo
	Public cm_caption
	Public cm_action
	Public cm_name
	Public cm_image
	Public cm_checked
	Public cm_Disabled
	Public cm_Message
	Public bManejadorError, bUltimoManejador, objErr,wret:=.F.
	Public cFile:="Menu.DBF"
	Public c1, c_dbf, f
	Public cm_Idioma:=2
	Public lescolha:= .t. 
	
	
    Set exclusive off
	If file(cfile)
		C1:=RAT(".",CFILE)
		C_DBF:=LEFT(CFILE,C1-1)
		
		USE &C_DBF NEW
		INDEX ON descend(FIELD->LINHA) TO &C_DBF

		Do while !eof()
			AADD(aListItens,{"","","","","","","","","","",.F.,.F.})
			Ains(aListItens,1)
			aListItens[1]:={(Alias())->TIPO,;		// 1
							(Alias())->CAPTIONP,;	// 2
							(Alias())->CAPTIONE,;	// 3
							(Alias())->CAPTIONI,;	// 4
							(Alias())->NOME,;		// 5
							(Alias())->ACTION,;		// 6
							(Alias())->IMAGE,;		// 7
							(Alias())->MESSAGEP,;	// 8	
							(Alias())->MESSAGEE,;	// 9
							(Alias())->MESSAGEI,;	// 10
							(Alias())->CHECKED,; 	// 11
							(Alias())->DISABLED}	// 12
			skip
		Enddo
		USE
	
		DEFINE WINDOW WinMain AT 0, 0 WIDTH 800 HEIGHT 600 TITLE "Menu DBF en tiempo de ejecución" MAIN 
			
			DEFINE MAIN MENU
	        FOR f:= 1 to len(aListItens)
				cm_tipo     :=aListItens[f][1]
				cm_caption  :=ALLTRIM(aListItens[f][2+cm_Idioma])
				cm_name     :=ALLTRIM(aListItens[f][5] )
				cm_action   := iif(EMPT(ALLTRIM(aListItens[f][6])),Nil,alltrim(aListItens[f][6]))
				cm_image    :=IIF(EMPT(ALLTRIM(aListItens[f][7])),NIL,ALLTRIM(aListItens[f][7]))
				cm_Message  :=IIF(EMPT(ALLTRIM(aListItens[f][8+cm_Idioma])),NIL,ALLTRIM(aListItens[f][8+cm_Idioma])) 
				cm_checked  :=aListItens[f][11]
				cm_Disabled :=aListItens[f][12]
		        If cm_tipo = "DEFINE POPUP"
					DEFINE POPUP cm_caption NAME cm_name
				ELSEIF cm_tipo = "MENUITEM"
					If !cm_checked
						IF cm_Disabled
							if cm_action = nil
								MENUITEM cm_caption ACTION nil Name cm_name IMAGE cm_image 
							else
								MENUITEM cm_caption ACTION { || &cm_action }
							endif	
						Else
							if cm_action = nil
								MENUITEM cm_caption ACTION nil  NAME cm_name IMAGE cm_image 
							else
								MENUITEM cm_caption ACTION { || &cm_action } NAME cm_name IMAGE cm_image 
							Endif
						Endif	
						
					Else
						IF cm_Disabled
							if cm_action = nil
								MENUITEM cm_caption ACTION nil NAME cm_name IMAGE cm_image CHECKED 
							else
								MENUITEM cm_caption ACTION { || &cm_action } NAME cm_name IMAGE cm_image CHECKED  
							endif	
						ELSE	
							if cm_action = nil
								MENUITEM cm_caption ACTION nil NAME cm_name IMAGE cm_image CHECKED 
							else	
								MENUITEM cm_caption ACTION { || &cm_action } NAME cm_name IMAGE cm_image CHECKED 
							endif	
						ENDIF	
					Endif
				ELSEIf cm_tipo = "SEPARATOR"
					SEPARATOR
				ELSEIF cm_tipo = "END POPUP"
					END POPUP
				Endif
			next	
				
			END MENU
			DEFINE STATUSBAR
				STATUSITEM "" 
				CLOCK WIDTH 85
				DATE
			END STATUSBAR
			
		END WINDOW
		
		Center Window WinMain
		Activate Window WinMain
	Else
		MsgStop(cFaltaMenu)
	Endif

Return Nil

*------------------------------------------------------------
* Ejemplo de definición de menú partiendo de una tabla
* (r) 2006, Roberto Sánchez
*------------------------------------------------------------
Function Salir()
  Release Window All
Return Nil

*------------------------------------------------------------
* Ejemplo de definición de menú partiendo de una tabla
* (r) 2006, Roberto Sánchez
*------------------------------------------------------------
Function AcercaDe()
  MsgInfo(cAcercaDe)
Return Nil
Last edited by danielmaximiliano on Fri Nov 18, 2011 10:09 pm, edited 1 time in total.
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
gvaronas
Posts: 109
Joined: Wed Aug 06, 2008 5:21 pm

Re: HMG4 - anybody know how to make a dynamic menu ?

Post by gvaronas »

Parece que el nombre de la función esta mal, dice MGSINFO y supongo que debe ser MSGINFO

Salu2,
GVS
User avatar
danielmaximiliano
Posts: 2607
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: HMG4 - anybody know how to make a dynamic menu ?

Post by danielmaximiliano »

Hola de nuevo, sinceramente no modifique el comentario de Gvaronas en el codigo, solo modifique la tabla demo.dbf agregando 'Nil' al campo Action, modifique 'Local xxxxx' por 'Public xxxxx' y el codigo funciona bien
pero miren estas imagenes y veran algo raro.
Propiedades de
Propiedades de
Propiedades IDE_2011-11-18_19-06-15.png (30.11 KiB) Viewed 9977 times
pero el Acerca de
Acerca de ?????
Acerca de ?????
Acercade.png (57.51 KiB) Viewed 9977 times
Comentarios ?????

Descargas aqui
MenuDBF.rar
Artchivos
(15.15 KiB) Downloaded 527 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
danielmaximiliano
Posts: 2607
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: HMG4 - anybody know how to make a dynamic menu ?

Post by danielmaximiliano »

Sin embargo

Code: Select all

*msginfo(GetCurrentFolder())
		Center Window WinMain
		Activate Window WinMain
	Else
		MsgStop(cFaltaMenu)
	Endif
error
error
Menu DBF en tiempo de ejecución_2011-11-18_19-42-59.png (54.67 KiB) Viewed 9976 times
Ok si

Code: Select all

msginfo(GetCurrentFolder())
		Center Window WinMain
		Activate Window WinMain
	Else
		MsgStop(cFaltaMenu)
	Endif
Compilacion OK
Compilacion OK
Menu DBF en tiempo de ejecución_2011-11-18_19-49-19.png (48.16 KiB) Viewed 9976 times
algo raro, no ?
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
ClaudioGalera
Posts: 47
Joined: Tue Jul 14, 2009 1:14 pm
Location: Mar del Plata, Argentina

Re: HMG4 - anybody know how to make a dynamic menu ?

Post by ClaudioGalera »

Gracias Daniel Maximiliano por responder y adaptarlo :)

Como has visto este demo bajo HMG3 funciona perfectamente. De hecho, lo he implementado en mis sistemas desde hace mucho tiempo.

Ahora al compilarlo bajo HMG4, cambia un poco por el tema de la estructura With Object .... END, ya que el preprocesador cambia el "END POPUP" por "END" y ahi es donde se descontrola todo :(

Code: Select all

	
IF ..............................................
...
DEFINE POPUP cm_caption NAME cm_name
...
...
ELSEIF cm_tipo = "END POPUP"
  END POPUP
Endif
por...

Code: Select all

IF ..............................................
...
With Object MENUPOPUP():New( "cm_name",, cm_caption )
...
...
ELSEIF cm_tipo = "END POPUP"
  end
Endif
Nuevamente gracias
Saludos

Claudio
Post Reply