How to recover the value of a control

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

How to recover the value of a control

Post by jparada »

Hi,

Of these two ways of recovering the value of a control:

Code: Select all

cValue := GetProperty ("frmMain", "name_control", "VALUE")
cValue := frmMain.name_control.VALUE
What is the difference, and in what context is "better" to use each of these.

Thanks.

Best Regards
Javier
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: How to recover the value of a control

Post by esgici »

jparada wrote:Hi,
...
What is the difference, and in what context is "better" to use each of these.
...
Hola Javier

The difference is only on style; first is "procedural" and second is "semi-oop" syntax.

So "better" is which you like :)

Saludos

--

Esgici
Viva INTERNATIONAL HMG :D
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: How to recover the value of a control

Post by jparada »

Merhaba Esgici,

Ahhh, thanks for the clarification and the "tip."

Saygılar

Best Regards
Javier
User avatar
srvet_claudio
Posts: 2224
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: How to recover the value of a control

Post by srvet_claudio »

Hola Javier,
jparada wrote: cValue := GetProperty ("frmMain", "name_control", "VALUE")
cValue := frmMain.name_control.VALUE
Hasta donde yo se no existen diferencias en cuanto a performance, la ultima forma es la mas convencional de usar pero no te permite usar macro sustitución, ej, si compilas esto de va dar error:

WinName := "frmMain"
cValue := &WinName.name_control.VALUE

Sin embargo esto funciona:
cValue := GetProperty (WinName, "name_control", "VALUE")

Yo utilizo GetProperty y SetProperty cuando creo en tiempo de ejecución algún control o ventana.
Por ejemplo, esto crea 10 label en la ventana Form_1 y les asigna un valor:

Code: Select all

#include "minigui.ch"

Function Main
DEFINE WINDOW Form_1;
		AT 0,0 ;
		WIDTH 600 HEIGHT 500 ;		
		MAIN 
        
        y=100
        x = 100
        FOR n = 1 TO 10
            Nombre := "Label_"+alltrim(str(n))
            @ y ,x LABEL &nombre OF Form_1
            y = y + 30
        NEXT

        FOR n = 1 TO 10
            Nombre := "Label_"+alltrim(str(n))
            SetProperty ("Form_1", Nombre , "VALUE", "Javier "+alltrim(str(n)))
        NEXT

END WINDOW

CENTER WINDOW Form_1		

ACTIVATE WINDOW Form_1
	
Return Nil

Espero haber podido ayudarte.
Saludos,
Claudio Soto.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
srvet_claudio
Posts: 2224
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: How to recover the value of a control

Post by srvet_claudio »

Hola Javier,
en el post anterior me olvide de mencionar que GetProperty y SetProperty se complementan con DoMethod.
Ej.

Form_1.Label_5.Show

es equivalente a:

DoMethod ("Form_1", "Label_5" , "Show")

Al ejemplo que te postee anteriormente agrégale este menu:

Code: Select all

DEFINE MAIN MENU
           DEFINE POPUP "Ver"
                  ITEM  "Ver Label 5"         ACTION DoMethod ("Form_1", "Label_5" , "Show")
                  ITEM  "Esconder Label 5" ACTION DoMethod ("Form_1", "Label_5" , "Hide")
           END POPUP
END MENU          
Saludos,
Claudio Soto
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: How to recover the value of a control

Post by mol »

In some cases, especially when you call one window from few others and you want to depend some controls from parent window, the procedure syntax is clear and easy.
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: How to recover the value of a control

Post by jparada »

Hi,

Thank you all for your responses.

Now I understand better.

Best Regards
Javier
Post Reply