Get list of all controls in a form

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Get list of all controls in a form

Post by serge_girard »

Hello,

I know there is a routine that lists all controls in a form, but I can't remember its name or where it is used.
Anybody an idea?
I want to capture all controls in my form in order to disavled/enable them on login-logout.

Thx, Serge
There's nothing you can do that can't be done...
jayadevu
Posts: 238
Joined: Tue May 19, 2009 7:10 am

Re: Get list of all controls in a form

Post by jayadevu »

Hello Serge,

This is the code borrowed from MiniGui Extended. May have to be modified to suit HMG.

Code: Select all

#include "minigui.ch"
/******************************************************************************/
Function _GetAllControlsInForm ( cFormName )
/******************************************************************************/
Local nFormHandle , i , nControlCount , aRetVal := {} , x
nFormHandle := GetFormHandle ( cFormName )
nControlCount := Len ( _HMG_aControlHandles )
For i := 1 To nControlCount
   If _HMG_aControlParentHandles[i] == nFormHandle
      If ValType( _HMG_aControlHandles[i] ) == 'N'
         IF ! Empty( _HMG_aControlNames[i] )
            If Ascan( aRetVal, _HMG_aControlNames[i] ) == 0
               Aadd( aRetVal, _HMG_aControlNames[i] )
            EndIf
         ENDIF
      ElseIf ValType( _HMG_aControlHandles [i] ) == 'A'
         For x := 1 To Len ( _HMG_aControlHandles[i] )
            IF !Empty( _HMG_aControlNames[i] )
               If Ascan( aRetVal, _HMG_aControlNames[i] ) == 0
                  Aadd( aRetVal, _HMG_aControlNames [i] )
               EndIf
            ENDIF
         Next x
      EndIf
   EndIf
Next i
Return  aRetVal

Warm regards,

Jayadev
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Get list of all controls in a form

Post by serge_girard »

Thanks Jayadev, In the meantime I borrowed somethings from Pablo (I think):

Code: Select all


PUBLIC aCtrls  := {}
PUBLIC lLOGIN  := .f.    

DEFINE WINDOW Form_1
   ...
END WINDOW

aCtrls := _GetArrayOfAllControlsForForm( "Form_1" )

 
FOR A = 1 TO LEN(aCtrls)
   IF 'BUTTON' $ UPPER(aCtrls [A] [2])  .OR. 'MENU' $ UPPER(aCtrls [A] [2]  )
      SetProperty('Form_1' , aCtrls [A] [1] ,  'Enabled', .f.   )
   ENDIF
NEXT
 

ACTIVATE WINDOW Form_1




FUNCTION LOGIN()
// LOGIN OK
lLOGIN								:= .t.    
FOR A = 1 TO LEN(aCtrls)
   IF 'BUTTON' $ UPPER(aCtrls [A] [2])  .OR. 'MENU' $ UPPER(aCtrls [A] [2]  )
      SetProperty('Form_1' , aCtrls [A] [1] ,  'Enabled', .t.   )
   ENDIF
NEXT





FUNCTION _GetArrayOfAllControlsForForm ( cFormName )
/**************************************************/
LOCAL nFormHandle , i , nControlCount , x
PRIVATE aRetVal1 := {} , aRetVal2 := {}

nFormHandle    := GetFormHandle ( cFormName )
nControlCount  := Len ( _HMG_SYSDATA [3] )

For i := 1 To nControlCount
   If _HMG_SYSDATA [4] [i] == nFormHandle
      If ValType( _HMG_SYSDATA [3] [i] ) == 'N'
	      AddCtrl(i)
      ElseIf ValType( _HMG_SYSDATA [3] [i] ) == 'A'
         For x := 1 To Len ( _HMG_SYSDATA [3] [i] )
			   AddCtrl(i)
         Next x
      Else
	      AddCtrl(i)
      EndIf
   EndIf
Next i
RETURN aRetVal1






FUNCTION AddCtrl(nIndx)
/***********************************/
If !Empty( _HMG_SYSDATA [2] [nIndx] )
   If Ascan( aRetVal2, _HMG_SYSDATA [2] [nIndx] ) == 0
      Aadd( aRetVal1, {_HMG_SYSDATA [2] [nIndx] , _HMG_SYSDATA [1] [nIndx]  } )
   EndIf
Else
   Aadd( aRetVal1, {_HMG_SYSDATA [2] [nIndx] , _HMG_SYSDATA [1] [nIndx] } )
EndIf
RETURN Nil
This works. After right logon all buttons and menu-popups are avaiable to the user, if not all is untouchable.

Thx, Serge
There's nothing you can do that can't be done...
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Get list of all controls in a form

Post by mol »

There was topic about autoadjust form on our forum with such a function....
Last edited by mol on Fri Feb 24, 2017 4:15 pm, edited 1 time in total.
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Get list of all controls in a form

Post by serge_girard »

Marek,

I think this is true, for resizing all controls maybe?
I used to code every button and menu apart but now all is done within a few lines. Adding or deleting a control is also easy!

Serge
There's nothing you can do that can't be done...
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Get list of all controls in a form

Post by mol »

Yes, for resizing all controls.
I can paste this function whe I'll be at home at evening
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Get list of all controls in a form

Post by mol »

Yes, for resizing all controls.
I can paste this function whe I'll be at home at evening
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Get list of all controls in a form

Post by Pablo César »

serge_girard wrote: Fri Feb 24, 2017 3:07 pm I borrowed somethings from Pablo (I think)
...
Adding or deleting a control is also easy!
It is very good to have this internal structure of _HMG_SYSDATA, very useful.

There are no problems Serge in making use of whatever I have published, I also live copying and adapting codes of publications from others. The best example is all that Roberto left for us all: this is OPEN SOURCE. And if it is published it is because it is being donated to the whole public.

No problems at all ! :D :P
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Anand
Posts: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: Get list of all controls in a form

Post by Anand »

Hi serge,

For similar requirement, I am using below code,

Code: Select all

//*****************************************************************************
static Function DisableAllButtons()
Local i,cCaption

For i = 1 to len( _HMG_aControlType)
    if AT("BUTTON", _HMG_aControlType [i]) > 0
        cCaption := GetProperty("Win_1", _HMG_aControlNames[i], "Caption")
        if "preview" $ lower(cCaption) .or. "cancel" $ lower(cCaption)
            //
        else
            _DisableControl( _HMG_aControlNames[i] , "Win_1" )
        endif
    elseif AT("TEXT", _HMG_aControlType [i]) > 0 .or. AT("CHECK", _HMG_aControlType [i]) > 0
        _DisableControl( _HMG_aControlNames[i] , "Win_1" )
    endif
next i

Return NIL
See if it is useful.

Regards,

Anand
Regards,

Anand

Image
Post Reply