BUTTON ACTION in a Loop

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

BUTTON ACTION in a Loop

Post by AUGE_OHR »

hi,

in a loop i want to create Button and assign a Function / Codeblock

Code: Select all

ACTION BlaBla(cField)
ACTION {|| BlaBla(cField) }
both Syntax work but i got wrong Result ... only "last cField" :(

so i try

Code: Select all

   cBlock := "{|| ShowMemo( "+cField+" )}"
   ACTION &cBlock
but that does not work ... no Error but not Result :o

so i try to use a Function before

Code: Select all

   cBlock := DetachLocal(cFIELD)
   ACTION cBlock

FUNCTION DetachLocal(cFIELD)
LOCAL cRet := "{|| ShowMemo( "+cFIELD+" ) }"
RETURN &(cRet)
but this also does not work :evil:

how is the right Syntax in HMG :idea:
need help please
have fun
Jimmy
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: BUTTON ACTION in a Loop

Post by andyglezl »

Tal vez... / Maybe...

cBlock := "{|| ShowMemo( "+cField+" )}"
ACTION EVAL( cBlock )
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: BUTTON ACTION in a Loop

Post by AUGE_OHR »

hi,
andyglezl wrote: Thu Dec 31, 2020 5:51 am

Code: Select all

   cBlock := "{|| ShowMemo( "+cField+" )}"
   ACTION EVAL( cBlock )
thx for try ...
Error BASE/1004 No exported method EVAL Parameter : [ 1] = C {||ShowMemo( FIELD->ANMERK )}
Called from (b)EVAL(0)
Called from (b)EDITDETAIL(1327)
IMHO cBlock is a String, not a Codeblock so i try

Code: Select all

   cBlock := &("{||ShowMemo( "+cFIELD+" )}")
this work ... but again only "last" Memo (of 3) which all Button show :(

---

under Xbase++ i use a Function to get a "Detach Local" as Codeblock.
this seems not to work under harbour HMG.

any other Tip :idea:
have fun
Jimmy
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: BUTTON ACTION in a Loop

Post by SALINETAS24 »

AUGE_OHR wrote: Thu Dec 31, 2020 5:29 am hi,

in a loop i want to create Button and assign a Function / Codeblock

Code: Select all

ACTION BlaBla(cField)
ACTION {|| BlaBla(cField) }

how is the right Syntax in HMG :idea:
need help please

Buenos dias,

Aquí te paso una posible solución a tu problemilla. Con esto ya sabes que botón ha sido pulsado, ahora ya es cuestión de tu imaginación. :idea:

Un saludo y vamos terminando con la cervecita del 2020, que ahora mismo se caduca y tenemos que empezar la de 2021.
FELIZ AÑO NUEVO A TODOS!!! :lol:

Code: Select all


// ------------------------------------------------------------------------
// --> Salinetas24 - CONTROL DE LA BOTONERIA
// ------------------------------------------------------------------------


#include <hmg.ch>

	DEFINE WINDOW Form_1        ;
		AT 0, 0                             ;
		WIDTH 475 HEIGHT 375     ; 
		TITLE ""                            ;
		ICON ""                             ;
		BACKCOLOR {128,128,255}  ;  
		MAIN                                ;
		NOMAXIMIZE NOSIZE        ;
		FONT "Arial" SIZE 9
	
		ON KEY ESCAPE ACTION  Form_1.Release
			
		DEFINE MAIN MENU
	
			POPUP "MENU"
				MENUITEM "Crea Botones " ACTION CreaBotones()
			END POPUP 			
	
		END MENU
			
	END WINDOW

	CENTER WINDOW Form_1
	ACTIVATE WINDOW Form_1

RETURN


// ----------------------------------------------------
// Creo cinco botones
PROC CreaBotones()
LOCAL nFor, cBut

	FOR nFor=1 TO 5
	cBut:="But_"+str(nFor,1)
	@ 30*nFor,30 BUTTON &cBut PARENT Form_1 CAPTION 'Botonico '+str(nFor)  WIDTH 150 HEIGHT 30 ;
				FONT "Arial" SIZE 09   ACTION Muestra(cBton:=GetProperty( ThisWindow.Name, 'FocusedControl'))  
	NEXT
	
RETURN

// ----------------------------------------------------
// Ahora ya sabes el boton que ha pulsado 
PROC Muestra(cVar)
	cTrozo:=SUBSTR(cVar,5)
	msgbox("HAS PULSADO EL BOTON "+cTrozo, "¡ATENCION!")
RETURN
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:
User avatar
serge_girard
Posts: 3308
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: BUTTON ACTION in a Loop

Post by serge_girard »

Jimmy

Try something like this

Code: Select all

bProc := &( "{ || &cFIELD }" )
EVAL(bProc)
Serge
There's nothing you can do that can't be done...
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: BUTTON ACTION in a Loop

Post by AUGE_OHR »

hi,

thx for Answer.

i have a DBF and want to show a Record.
i do use a loop and all "normal" Field work fine as i assign it to VALUE "before create"
for MEMO i want to use a BUTTON to call a Function to show MEMO

Code: Select all

   FOR i := 1 TO iMax
      cFIELD := aStruc[ i ] [ DBS_NAME ]

      DEFINE BUTTON &cObj
         ... 
         ACTION ShowMemo(cFIELD)
      END BUTTON
   NEXT
this Way it show only last MEMO (of 3) :(
i think it is called "late bindings" but how it work under harbour HMG :idea:
have fun
Jimmy
User avatar
serge_girard
Posts: 3308
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: BUTTON ACTION in a Loop

Post by serge_girard »

cFIELD := aStruc[ i ] [ DBS_NAME ]

is cFIELD always the same?
There's nothing you can do that can't be done...
edk
Posts: 998
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: BUTTON ACTION in a Loop

Post by edk »

AUGE_OHR wrote: Thu Dec 31, 2020 5:29 am hi,

in a loop i want to create Button and assign a Function / Codeblock

Code: Select all

ACTION BlaBla(cField)
ACTION {|| BlaBla(cField) }
both Syntax work but i got wrong Result ... only "last cField" :(

so i try

Code: Select all

   cBlock := "{|| ShowMemo( "+cField+" )}"
   ACTION &cBlock
but that does not work ... no Error but not Result :o

so i try to use a Function before

Code: Select all

   cBlock := DetachLocal(cFIELD)
   ACTION cBlock

FUNCTION DetachLocal(cFIELD)
LOCAL cRet := "{|| ShowMemo( "+cFIELD+" ) }"
RETURN &(cRet)
but this also does not work :evil:

how is the right Syntax in HMG :idea:
need help please
Is this a similar issue ? http://hmgforum.com/viewtopic.php?p=60100#p60100

IMHO it should be

Code: Select all

   cProc := "ShowMemo( '" + cFIELD + "' ) "
   ACTION &cProc  
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: BUTTON ACTION in a Loop

Post by SALINETAS24 »

AUGE_OHR wrote: Thu Dec 31, 2020 7:39 pm hi,

thx for Answer.

i have a DBF and want to show a Record.
i do use a loop and all "normal" Field work fine as i assign it to VALUE "before create"
for MEMO i want to use a BUTTON to call a Function to show MEMO

Code: Select all

   FOR i := 1 TO iMax
      cFIELD := aStruc[ i ] [ DBS_NAME ]

      DEFINE BUTTON &cObj
         ... 
         ACTION ShowMemo(cFIELD)
      END BUTTON
   NEXT
this Way it show only last MEMO (of 3) :(
i think it is called "late bindings" but how it work under harbour HMG :idea:
Hola Auge,

En estos casos estaría bien que pasaras un código ejecutable, así lo modificariamos sin necesidad de tener que escribir tanto, pero como es navidad estas de suerte.

Espero que te sirva.., un abrazo y vamos con una cervecita bien fresquita para empezar el año.

Code: Select all

// ------------------------------------------------------------------------
// --> Salinetas24 - CONTROL DE LA BOTONERIA
// ------------------------------------------------------------------------
// En el año de nuestro Señor del 2021, y siendo el primer dia de Enero
// a la espera de poder tomarnos una cervecta con amigo y poder alternar
// sin mascarilla, aqui estamos, sin apenas libertad de movimiento.., pasando
// el tiempo programando....
// Espero que te sirva 
// ------------------------------------------------------------------------

#include <hmg.ch>

PRIVATE  aEstructura:={}
PRIVATE  aCampos:={}


	AgendaOpen()
	aEstructura:=Agenda->(DbStruct())

	//--> Nombre del Campo
	FOR nFor=1 TO LEN(aEstructura)
		AADD(aCampos,aEstructura [nFor][1])
	NEXT

	
	
	DEFINE WINDOW Form_1        ;
		AT 0, 0                             ;
		WIDTH 475 HEIGHT 375     ; 
		TITLE ""                            ;
		ICON ""                             ;
		BACKCOLOR {128,128,255}  ;  
		MAIN                                ;
		NOMAXIMIZE NOSIZE        ;
		FONT "Arial" SIZE 9
	
		ON KEY ESCAPE ACTION  Form_1.Release
			
		DEFINE MAIN MENU
	
			POPUP "MENU"
				MENUITEM "Crea Botones " ACTION CreaBotones(aCampos)
			END POPUP 			
	
		END MENU
			
	END WINDOW

	CENTER WINDOW Form_1
	ACTIVATE WINDOW Form_1

RETURN


// ----------------------------------------------------
// Creo cinco botones
PROC CreaBotones()
LOCAL nFor, cBut, cMascara
LOCAL aField[4]
PUBLIC xVar, xFie

	// Busca el resgistro Dbseek
	Agenda->(DbGoto(1))   
	// Carga datos
    aField[1]:=Agenda->CODIGO
	aField[2]:=Agenda->NOMBRE
	aField[3]:=Agenda->DIRECCION
	aField[4]:=Agenda->MEMO
	

	// LA PRESENTACION
	FOR nFor=1 TO 4
		cLbl:="SAY_"+STR(nFor,1)
		@ 30*nFor,10 LABEL &cLbl PARENT Form_1  VALUE aCampos[nFor] AUTOSIZE TRANSPARENT
	NEXT
	
	// LA PETICION
	FOR nFor=1 TO 4
		cGet:="Get_"+STR(nFor,1)
		DO CASE 
			CASE aEstructura[nFor,2] == "M"   // Es un "MEMO"
					xVar:=cGet
					xFie:=aField[nFor]
				    nVar:= IF(aEstructura[nFor,3]*10<50, 50, IF(aEstructura[nFor,3] * 10 > 250, 250,aEstructura[nFor,3] * 10)  ) 
*					@ 30*nFor,120 LABEL &cGet PARENT Form_1 VALUE aField[nFor] WIDTH nVar-50
					@ 30*nFor,250 BUTTON Btn_1 PARENT Form_1 CAPTION "MEMO" WIDTH 60 HEIGHT 27 ;
						ACTION  EditaMemo(xVar,xFie)
			CASE  aEstructura[nFor,2] == "N"        // Campo tipo numerico
			    	cMascara := REPLICATE( "9", aEstructura[nFor,3] )
					IF aEstructura[nFor,4]!=0           // Tiene decimales
						cMascara := REPLICATE( "9", aEstructura[nFor,3]-(aEstructura[nFor,4]+1) )
						cMascara += "."
						cMascara += REPLICATE( "9", (aEstructura[nFor,4] ) )
					ENDIF	
					@ 30*nFor,120 TEXTBOX &cGet PARENT Form_1 VALUE aField[nFor] ;
						WIDTH  IF(aEstructura[nFor,3]*10<50, 50, IF(aEstructura[nFor,3] * 10 > 250, 250,aEstructura[nFor,3] * 10)  ) ;
                        NUMERIC INPUTMASK cMascara 
			OTHERWISE   // EL RESTO..., ya me he cansado.
					@ 30*nFor,120 TEXTBOX &cGet PARENT Form_1  VALUE aField[nFor]  ;
						WIDTH IF(aEstructura[nFor,3]*10<50, 50, IF(aEstructura[nFor,3] * 10 > 250, 250,aEstructura[nFor,3] * 10)  ) ;
						MAXLENGTH aEstructura[nFor,3] 
		ENDCASE
	NEXT

	@ 20,320 BUTTON  Actua_1  PARENT Form_1 CAPTION "Actualizar"   WIDTH 120 HEIGHT 30 ;
			ACTION   VerValores(aField)
	
	
	
	
/*	
	cBut:="But_"+str(nFor,1)
	@ 30*nFor,30 BUTTON &cBut PARENT Form_1 CAPTION 'Botonico '+str(nFor)  WIDTH 150 HEIGHT 30 ;
				FONT "Arial" SIZE 09   ACTION Muestra(cBton:=GetProperty( ThisWindow.Name, 'FocusedControl'))  
*/	
	
RETURN

// ---------------------------------------------------
// Comprueba nuevos valores
PROC VerValores(aField)

	FOR nFor=1 TO LEN(aField)
   		cGet:="Get_"+Str(nFor,1)
		aField[nFor]:= GetProperty("Form_1",cGet,"Value") 
	NEXT
	// Y ahora los replace
	Agenda->(DBAppend())
	REPLACE Agenda-> CODIGO    WITH aField[1]
	REPLACE Agenda-> NOMBRE    WITH aField[2]
	REPLACE Agenda-> DIRECCION WITH aField[3]
	REPLACE Agenda-> MEMO      WITH aField[4]
	msgdebug(aField)
RETURN

// ---------------------------------------------------
// Edita MEMO
PROC EditaMemo(xVar,xFie)
    @ 150,10 editbox &xVar PARENT Form_1 VALUE xFie  WIDTH  250 HEIGHT 90 NOHSCROLL 
RETURN

// ----------------------------------------------------
// Ahora ya sabes el boton que ha pulsado 
PROC Muestra(cVar)
	cTrozo:=SUBSTR(cVar,5)
	msgbox("HAS PULSADO EL BOTON "+cTrozo, "¡ATENCION!")
RETURN



Function AgendaOpen()
Local aarq := {}       
Local aDados   := {}
   If ! FILE( "AGENDA.DBF" )
      Aadd( aArq , { 'CODIGO'  , 'N'   , 04    , 0 } )
      Aadd( aArq , { 'NOMBRE '       , 'C'   , 40    , 0 } )
      Aadd( aArq , { 'DIRECCION'    , 'C'   , 40    , 0 } )
      Aadd( aArq , { 'MEMO'      , 'M'   , 25    , 0 } )
      DBCreate( "AGENDA.DBF" , aArq  )     
   EndIf
   Use AGENDA Alias Agenda new shared

Return Nil

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:
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: BUTTON ACTION in a Loop

Post by franco »

Maybe
select table first

ACTION BlaBla(Field1) // gives field1 name
ACTION {|| BlaBla(Field1) }

Function blabla(f1)
msgbox(f1) // = field1 name
msgbox(&f1) // = field1 value
return

I think this works
All The Best,
Franco
Canada
Post Reply