Page 1 of 1

How to recover the value of a control

Posted: Mon Apr 12, 2010 10:42 pm
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

Re: How to recover the value of a control

Posted: Mon Apr 12, 2010 11:00 pm
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

Re: How to recover the value of a control

Posted: Mon Apr 12, 2010 11:09 pm
by jparada
Merhaba Esgici,

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

Saygılar

Best Regards
Javier

Re: How to recover the value of a control

Posted: Mon Apr 12, 2010 11:27 pm
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.

Re: How to recover the value of a control

Posted: Tue Apr 13, 2010 12:37 am
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

Re: How to recover the value of a control

Posted: Tue Apr 13, 2010 6:46 am
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.

Re: How to recover the value of a control

Posted: Tue Apr 13, 2010 3:09 pm
by jparada
Hi,

Thank you all for your responses.

Now I understand better.

Best Regards
Javier