Crear Menus desde archivo texto
Crear Menus desde archivo texto
Hola a Todos,
Como crear un menu desde archivo texto?
Atentamente
Julio Ponce
Como crear un menu desde archivo texto?
Atentamente
Julio Ponce
- jrestojeda
- Posts: 543
- Joined: Wed Jul 04, 2007 3:51 pm
- Location: Buenos Aires - Argentina
Re: Crear Menus desde archivo texto
Hola amigo...
Usa un MEMOREAD y carga el archivo de texto en un Array, de ahi te olvidas del archivo de texto y trabaja con el Array.
Espero te sirva la idea.
Usa un MEMOREAD y carga el archivo de texto en un Array, de ahi te olvidas del archivo de texto y trabaja con el Array.
Code: Select all
// FUNCION PARA LEER UN ARCHIVO DE TEXTO //
Function LeoTxt()
Local Archivo,mVar,CanLineas,Q,Li,aMenu[0]
mVar:=Curdir()+"MENU.txt"
Archivo :=MEMOREAD(mVar)
CantLineas:=MLCOUNT(Archivo)
FOR Q=1 TO CantLineas
Li:=MEMOLINE(Archivo,80,Q)
AADD(aMenu,Li)
NEXT
Return nil
//
Ojeda Esteban Eduardo.
Buenos Aires - Argentina.
FWH - PellesC - DBF/CDX - ADS - Gloriosos .Bat - MySql - C# .net - FastReport
Skype: jreduojeda
Buenos Aires - Argentina.
FWH - PellesC - DBF/CDX - ADS - Gloriosos .Bat - MySql - C# .net - FastReport
Skype: jreduojeda
Re: Crear Menus desde archivo texto
Gracias pero como lleno el menu?jrestojeda wrote:Hola amigo...
Usa un MEMOREAD y carga el archivo de texto en un Array, de ahi te olvidas del archivo de texto y trabaja con el Array.
Espero te sirva la idea.Code: Select all
// FUNCION PARA LEER UN ARCHIVO DE TEXTO // Function LeoTxt() Local Archivo,mVar,CanLineas,Q,Li,aMenu[0] mVar:=Curdir()+"MENU.txt" Archivo :=MEMOREAD(mVar) CantLineas:=MLCOUNT(Archivo) FOR Q=1 TO CantLineas Li:=MEMOLINE(Archivo,80,Q) AADD(aMenu,Li) NEXT Return nil //
Atentamente
Julio Ponce
Re: Crear Menus desde archivo texto
Julio, asi como te indica Esteban
Tenés que leer la tabla aMenu
y harias así
MENU oMenu 2007
MENU
MENUITEM aMenu[1] MESSAGE "mensage" ACTION tufuncion()
ENDMENU
ENDMENU
Saludos
Adhemar
Tenés que leer la tabla aMenu
y harias así
MENU oMenu 2007
MENU
MENUITEM aMenu[1] MESSAGE "mensage" ACTION tufuncion()
ENDMENU
ENDMENU
Saludos
Adhemar
Saludos,
Adhemar C.
Adhemar C.
Re: Crear Menus desde archivo texto
Ya lo logre hacer así, pero como poner los Action tambien en la matriz, si no de que sirve tener el archivo texto,
Esto lo quiero para que el usuario pueda crear su propio menu desde el archivo texto sin tener que compilar el programa.
Atentamente
Julio Ponce
Esto lo quiero para que el usuario pueda crear su propio menu desde el archivo texto sin tener que compilar el programa.
Atentamente
Julio Ponce
acuellar wrote:Julio, asi como te indica Esteban
Tenés que leer la tabla aMenu
y harias así
MENU oMenu 2007
MENU
MENUITEM aMenu[1] MESSAGE "mensage" ACTION tufuncion()
ENDMENU
ENDMENU
Saludos
Adhemar
- joseluisysturiz
- Posts: 2024
- Joined: Fri Jan 06, 2006 9:28 pm
- Location: Guatire - Caracas - Venezuela
- Contact:
Re: Crear Menus desde archivo texto
??? es buena la idea, pero creo que puedes separar por comas (,) el item del menu y luego la funcion y se la pasas a un macro, lo puedes hacer en forma vertical asi lo lees por numero de linea o en un campo MEMO, nose, digo, es una idea que se me vino derepente, saludos, seguire esto que se ve bueno, aunque por alli habia algo parecido para personaliozar los menues a traves del nivel del usuario para restringirlo.
Dios no está muerto...
Gracias a mi Dios ante todo!
Gracias a mi Dios ante todo!
Re: Crear Menus desde archivo texto
Julio trata de esta manera
Contenido del archivo de texto: MENU.TXT
Opcion Menu1,Realiza lo siguiente,FUNCION1()
Opcion Menu2,Realiza esto,FUNCION2()
También podés hacerlo con una tabla de 3 columnas
Espero te sirva
Saludos
Adhemar
Contenido del archivo de texto: MENU.TXT
Opcion Menu1,Realiza lo siguiente,FUNCION1()
Opcion Menu2,Realiza esto,FUNCION2()
Code: Select all
Function CreaMenu()
Local oMenu
If !File('MENU.DBF')
DbCreate( "MENU", { { "ITEM", "C", 15,0 },{ "MSG", "C",25,0 },{ "FUNCION", "C", 12,0 } }, "DBFCDX" )
ENDIF
USE MENU NEW EXCLUSIVE
DBZAP()
APPEND FROM "MENU.TXT" DELIMITED
DBGOTOP()
MENU oMenu 2007
MENUITEM "&Datos" MESSAGE "Datos generales"
MENU
Do While !Eof()
MENUITEM ITEM MESSAGE MSG ACTION &FUNCION
DbSkip()
Enddo
ENDMENU
ENDMENU
Espero te sirva
Saludos
Adhemar
Saludos,
Adhemar C.
Adhemar C.
Re: Crear Menus desde archivo texto
Aqui Tienes Esto, Espero te ayude
Aunque está hecho para mysql y Dbase
Saludos...
Aunque está hecho para mysql y Dbase
Code: Select all
//------------------------------------------------
// Carga Menu Principal desde una Tabla (DBASE Y MYSQL)
// VERSION polivalente
// por: Angel Blanco
// Valencia, Venezuela
// Agosto-2.005
// se apoya en este Comando para agregar seleccion en menu (CLASE TMENU)
// MenuAddItem( <cPrompt>, <cMsg>,;
// <.checked.>, [ Upper(<(enable)>) == "ENABLED" ],;
// [\{|oMnuItem|<uAction>\}],;
// <cBmpFile>, <cResName>, <oMnu>, <bAction>, <nState>, <nVirtKey>,;
// <.help.>, <nHelpId>, [<{uWhen}>], <.break.> )
FUNCTION MaiMenu( oWnd,oNamUsr,cTabla )
LOCAL oMnu,c_Accion,n_mnu,n_CountReg:=0
LOCAL a_Op:={},n_regist
LOCAL cComand,oQuery
LOCAL lMySql:=.t. // para que sea por sql
CURSORWAIT()
IF lMySql
cComand:='SELECT SysAccTot.IntMenu,'+;
'SysAccTot.IntOpcion,'+;
'SysAccTot.VchSeleccion,'+;
'SysAccTot.VchMsg,'+;
'SysAccTot.VchAccion,'+;
'SysAccTot.IntMenuSal,'+;
'SysAccTot.VchCondPres,'+;
'SysAccTot.VchCondAcc '+;
'FROM '+cDtComun+'.SysAccTot '+;
'WHERE SysAccTot.VchModulo ="HCM" AND '+;
'SysAccTot.VchTipo = "M" '+;
'ORDER BY SysAccTot.IntMenu,'+;
'SysAccTot.IntOpcion'
oQuery :=TMSQuery():New( oDtBase )
oQuery:Open( cComand )
// Traemos el resultado a nuestro cliente
IF ( oQuery:nRowCount>0 )
// necesario para garantizar la organizacion de la informacion
DO WHILE !oQuery:lEof
AADD(a_Op,{oQuery:xFieldGet( 1 ),; // MENU
oQuery:xFieldGet( 2 ),; // OPCION
oQuery:xFieldGet( 3 ),; // SELECCION
oQuery:xFieldGet( 4 ),; // MSG
oQuery:xFieldGet( 5 ),; // ACCION
oQuery:xFieldGet( 6 ),; // MENU SALIDA
IIF(LEN(ALLTRIM(oQuery:xFieldGet( 7 )))=0,".T.",ALLTRIM(oQuery:xFieldGet( 7 ))),;
IIF(LEN(ALLTRIM(oQuery:xFieldGet( 8 )))=0,".T.",ALLTRIM(oQuery:xFieldGet( 8 )))})
n_CountReg +=1
oQuery:Fetch()
ENDDO
ENDIF
oQuery:Close()
ELSE
IF FILE("MENU.NTX")
DELETE FILE MENU.NTX
ENDIF
*USE C:\FUENTES\HCM\MENU.MNU SHARED alias MNU
USE &cTabla SHARED alias MNU
INDEX ON str(_field->menu,2,0)+str(_field->opcion,2,0) to MENU.NTX
//
// COPIANDO TABLA A ARREGLO
DO WHILE !MNU->(EOF())
AADD(a_Op,{MNU->MENU,;
MNU->OPCION,;
MNU->SELECCION,;
MNU->MSG,;
MNU->ACCION,;
MNU->MENUSAL,;
IIF(LEN(ALLTRIM(MNU->COND_PRES))=0,".T.",ALLTRIM(MNU->COND_PRES)),;
IIF(LEN(ALLTRIM(MNU->COND_ACC))=0,".T.",ALLTRIM(MNU->COND_ACC))})
n_CountReg +=1
MNU->(DBSKIP())
ENDDO
use
ENDIF
IF n_CountReg>0
n_regist := 1
oMnu := MenuBegin() // inicia menu
AgregaNivel(a_Op,1,@oMnu,n_CountReg) // GENERA MENU
ENDIF
RETURN oMnu
//------------------------------------------------
// AGREGA NIVEL DE MENU (CONCURRENTE)
// VERSION polivalente
//
static PROCEDURE AgregaNivel(a_Op,n_nummenu,oMnu,n_CountReg)
LOCAL n_mnu,c_Accion,n_regist:=1,cPres,cWhen
DO WHILE a_Op[n_regist,1]<>n_nummenu
n_regist +=1
IF n_regist>n_CountReg
EXIT
ENDIF
ENDDO
IF n_regist<=n_CountReg
IF n_nummenu>1
MenuBegin() // comienza menu
ENDIF
DO WHILE a_Op[n_regist,1]=n_nummenu // solo para ESE MENU
cPres:=a_Op[n_regist,7]
cWhen:=a_Op[n_regist,8]
if &cPres
DO CASE
CASE LEN(alltrim(a_Op[n_regist,5])) =0 // No tiene accion!!!
IF a_Op[n_regist,6] >0 // Llama a otro menu
MenuAddItem(alltrim(a_Op[n_regist,3]),alltrim(a_Op[n_regist,4]),.F.,&cWhen ,,,,oMnu,,,,.F., )
n_mnu:=n_regist // guarda el registro para restaurar
AgregaNivel(a_Op,a_Op[n_regist,6],@oMnu,n_CountReg) // Agrega otro nivel de menu
n_regist:=n_mnu // restaura al registro
ELSE // agrega Espacio
IF LEN(alltrim(a_Op[n_regist,3]))=0 // si no tiene etiqueta
MenuAddItem(,,.F.,,,,,oMnu,,,,.F., ) // Agrega Espacio
ELSE // si tiene etiqueta
c_Accion:="{ || msgAlert('Por Implementar') }" // la presenta
MenuAddItem(alltrim(a_Op[n_regist,3]),alltrim(a_Op[n_regist,4]),.F.,&cWhen,&c_Accion,,,oMnu,,,,.F., )
ENDIF
ENDIF
CASE LEN(alltrim(a_Op[n_regist,5])) >0 // Es un Renglon de menu
c_Accion:="{ || "+alltrim(a_Op[n_regist,5])+" }"
MenuAddItem(alltrim(a_Op[n_regist,3]),alltrim(a_Op[n_regist,4]),.F.,&cWhen,&c_Accion,,,oMnu,,,,.F., )
ENDCASE
ENDIF
n_regist +=1 // nuevo registro
IF n_regist>n_CountReg
EXIT
ENDIF
ENDDO
MenuEnd() // fin de menu
ENDIF
RETURN
Saludos
Angel, Valencia, Venezuela
xH .997 - FW 7.9 - BCC55 - WorkShop - MySql
Angel, Valencia, Venezuela
xH .997 - FW 7.9 - BCC55 - WorkShop - MySql
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Crear Menus desde archivo texto
Julio,
Tienes un ejemplo en FWH\samples\TestMnu.prg que construye el menú desde una DBF
Tienes un ejemplo en FWH\samples\TestMnu.prg que construye el menú desde una DBF
Re: Crear Menus desde archivo texto
Si utilizo esta funcion siempre me agrega la nueva opcion al final de DBF
Existe alguna forma de organizarlo controlado ?
Existe alguna forma de organizarlo controlado ?