This.Name in DEFINE CONTROL CONTEXT MENU

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

This.Name in DEFINE CONTROL CONTEXT MENU

Post by andyglezl »

Hola a todos

Estoy haciendo una prueba con "DEFINE CONTROL CONTEXT MENU" pero no logro enviar el nombre de dicho control
hacia una determinada función.

Si oprimo el boton izquierdo en un control "LABEL" con "This.Name" si es correcto el nombre que recibe dicha función
pero al hacerlo con el boton derecho, en el Context Menu - MENUITEM "Edita" ACTION { || Mensaje( nR, nC, cCtrl1 ) }
me despliega siempre el nombre del control anterior.

Alguien tendrá idea de como resolverlo ??

Gracias.
---------------------------------------------------------------------------------------------------------------------------------------------------
Hello everyone

I'm doing a test with "DEFINE CONTROL CONTEXT MENU" but I can not send the name of that control
towards a certain function.

If I press the left button in a "LABEL" control with "This.Name" if the name that receives that function is correct
but when doing it with the right button, in the Context Menu - MENUITEM "Edit" ACTION {|| Mensaje(nR, nC, cCtrl1)}
I always display the name of the previous control.

Someone will have an idea how to solve it ??

Thank you.

Code: Select all

#include "hmg.ch"

FUNCTION Main
	LOCAl i1, i2
	PUBLIC cCtrlName, nR := 0,	nC := 0
	
	DEFINE WINDOW Form_1 AT 0 , 0 WIDTH 1024 HEIGHT 650 NOSIZE NOMAXIMIZE BACKCOLOR GRAY
		nRen := 50	;	nCol := 10		;	nRenGridColor := 20
		FOR i1 = 1 TO 5
			FOR i2 = 1 TO 8
				cCtrl1 := "LBL_" + STRZERO( i1, 2 ) + STRZERO( i2, 2 )
				@ nRen , nCol LABEL &cCtrl1. OF Form_1 VALUE ""  WIDTH 100 HEIGHT 22 FONT "Consolas" SIZE 9 FONTCOLOR BLACK BACKCOLOR CYAN ; 
							  ACTION  { || nR := VAL( SUBSTR( This.Name, 5, 2 ) ), nC := VAL( SUBSTR( This.Name, 7, 2 ) ), cCtrlName := This.Name, ;
											Mensaje( nR, nC, This.Name ) }	CENTERALIGN
				SET CONTROL &cCtrl1. OF Form_1 STATICEDGE
				nCol += 100
				DEFINE CONTROL CONTEXT MENU &cCtrl1. OF Form_1
					//  COMO ENVIAR EL NOMBRE DE LOS CONTROLES LABEL A LA FUNCION MENSAJE() EN TIEMPO DE EJECUCION
					//  HOW TO SEND THE LABEL CONTROLS NAME TO THE MENSAJE() FUNCTION AT EXECUTION TIME
					*MENUITEM "Edita" ACTION { ||  Mensaje( nR, nC, This.Name ) } TOOLTIP "cToolTipText"		// ERROR !
					*MENUITEM "Edita" ACTION { ||  Mensaje( nR, nC, &cCtrl1. ) } TOOLTIP "cToolTipText"			// ERROR !
					*MENUITEM "Edita" ACTION { ||  Mensaje( nR, nC, cCtrl1 ) } TOOLTIP "cToolTipText"			// does not display ERROR but is the name of the previous CONTROL!
					*MENUITEM "Edita" ACTION { ||  Mensaje( nR, nC, ( cCtrl1 ) ) } TOOLTIP "cToolTipText"		// does not display ERROR but is the name of the previous CONTROL!
					MENUITEM "Edita" ACTION { ||  Mensaje( nR, nC, cCtrlName ) } TOOLTIP "cToolTipText"			// does not display ERROR but is the name of the previous CONTROL!
					SEPARATOR
					MENUITEM "Copia" ACTION Nil TOOLTIP "cToolTipText"
					SEPARATOR					
					MENUITEM "Pega"  ACTION Nil TOOLTIP "cToolTipText"
				END MENU				
			NEXT
			nCol := 10
			nRen += 22
		NEXT
		
	END WINDOW
    CENTER WINDOW Form_1
    ACTIVATE WINDOW Form_1
	
RETURN

FUNCTION Mensaje( x, y, cCt )
	msgdebug( x, y, cCt )
RETURN
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
luisvasquezcl
Posts: 1258
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Contact:

Re: This.Name in DEFINE CONTROL CONTEXT MENU

Post by luisvasquezcl »

Quita el bloque de código del action
Dejalo MENUITEM "pegar" ACTION Mensaje("test")
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: This.Name in DEFINE CONTROL CONTEXT MENU

Post by andyglezl »

Gracias Luis, pero me resulta igual.

Quiero enviar como parametro el nombre del "CONTEXT MENU" a la funciòn Mensaje() que va a variar al momento
de la ejecución dependiendo en que celda oprima el botón derecho.
--------------------------------------------------------------------------------------------------------------------------------------------
Thanks Luis, but it's the same for me.

I want to send as parameter the name of the "CONTEXT MENU" to the mensaje() function that will vary at the moment
of the execution depending on which cell press the right button.



DEFINE CONTROL CONTEXT MENU &cCtrl1. OF Form_1

MENUITEM "Edita" ACTION { || Mensaje( nR, nC, cCtrl1 ) } TOOLTIP "cToolTipText"

contextmenu.png
contextmenu.png (197.04 KiB) Viewed 2533 times
Andrés González López
Desde Guadalajara, Jalisco. México.
martingz
Posts: 394
Joined: Wed Nov 18, 2009 11:14 pm
Location: Mexico

Re: This.Name in DEFINE CONTROL CONTEXT MENU

Post by martingz »

Andy esto es normal si la ultima celda (Label) que creaste esla que tiene el foco, por consecuencia al dar click derecho para el menu contextual siempre te dara esos valores, tienes que poner el foco en la celda que deseas, si das click en cualquier celda y despues click derecho para el menu contextual veras a lo que me refiero.


saludos
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: This.Name in DEFINE CONTROL CONTEXT MENU

Post by KDJ »

Andy

Here is one of the ways:

Code: Select all

MENUITEM "Edita" NAME &("Edit" + cCtrl1) ACTION { ||  Mensaje( Val(SubStr(This.NAME, 9, 2)), Val(SubStr(This.NAME, 11, 2)), SubStr(This.NAME, 5) ) } TOOLTIP "cToolTipText"
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: This.Name in DEFINE CONTROL CONTEXT MENU

Post by andyglezl »

Hola Martin, gracias.

Asi es, estoy de acuerdo porque eso es lo que me arrojan las pruebas,
pero yo asumí que al dar click con el botón derecho podía saber y utilizar
lo que se puede hacer con el botón izquierdo.

Pero me saltan varias dudas:

1.- Como puedo saber el nombre de este control DEFINE CONTROL CONTEXT MENU <ControlName> en tiempo de ejecucion.
2.- Como puedo saber el nombre de algún item, MENUITEM <cItemCaption> ACTION <bBlock> [ NAME <MenuItemName>]
Ya que al parecer el This. Name no funciona (o no está implementado) en este control.

Otra cosa es lo que comentas de que el control debe tener el foco para utilizar con el botón izquerdo el
CONTEXT MENU ya que al ser un CONTROL LABEL no le puedo (o no sé) dar el foco.
-------------------------------------------------------------------------------------------------------------------------------------------------------
Hello Martin, thank you.

That's right, I agree because that is what the evidence throws at me,
but I assumed that by clicking with the right button I could know and use
what can be done with the left button.

But I miss several questions:

1.- How can I know the name of this control DEFINE CONTROL CONTEXT MENU <ControlName> at run time.
2.- How can I know the name of an item, MENUITEM <cItemCaption> ACTION <bBlock> [NAME <MenuItemName>]
Since apparently This.Name does not work (or is not implemented) in this control.

Another thing is what you mention that the control must have the focus to use with the left button the
CONTEXT MENU since being a CONTROL LABEL I can not (or I do not know) give the focus.
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: This.Name in DEFINE CONTROL CONTEXT MENU

Post by andyglezl »

KDJ wrote: Fri Aug 03, 2018 3:25 pm Andy

Here is one of the ways:

Code: Select all

MENUITEM "Edita" NAME &("Edit" + cCtrl1) ACTION { ||  Mensaje( Val(SubStr(This.NAME, 9, 2)), Val(SubStr(This.NAME, 11, 2)), SubStr(This.NAME, 5) ) } TOOLTIP "cToolTipText"
Gracias KDJ
Ya lo había probado con:
*MENUITEM "Edita" ACTION { || Mensaje( nR, nC, This.Name ) } TOOLTIP "cToolTipText" // COMPILING ERROR !
y me despliega error al compilar, pero voy a probar de nuevo con tu sugerencia. Gracias
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks KDJ
I had already tried it with:
* MENUITEM "Edit" ACTION {|| Message (nR, nC, This.Name)} TOOLTIP "cToolTipText" // COMPILING ERROR!
and I deploy error when compiling, but I will try again with your suggestion. Thank you
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: This.Name in DEFINE CONTROL CONTEXT MENU

Post by andyglezl »

Muchas gracias KDJ, con tu sugerencia funciona perfecto !
--------------------------------------------------------------------------
Thank you very much KDJ, with your suggestion it works perfect!


P.D.
Al parecer aquí, si no lo nombras no existe This.Name
---------------------------------------------------------------------
Apparently here, if you do not name it, there is no This.Name

MENUITEM "Edita" NAME &("Edit" + cCtrl1) ACTION { || Mensaje( Val(SubStr(This.NAME, 9, 2)), Val(SubStr(This.NAME, 11, 2)), SubStr(This.NAME, 5) ) } TOOLTIP "cToolTipText"
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply