List of all defined controls in a form

Moderator: Rathinagiri

Post Reply
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

List of all defined controls in a form

Post by l3whmg »

Hi at all,
I don't know if exist (I don't find / don't read about), but is there a function that return an array with the names of all defined controls in a form?
Luigi from Italy
www.L3W.it
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: List of all defined controls in a form

Post by l3whmg »

Hi,
and sorry :oops: : after I've inserted this post I understand that it's not so clear the use.
I want execute a loop to disable all the controls in a form. Example:

Code: Select all

aControl := MiniGuiFunction()
FOR n := 1 TO LEN(aControl)
 aControl[n].Enabled := .F.
NEXT n
Bye
Luigi from Italy
www.L3W.it
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: List of all defined controls in a form

Post by Rathinagiri »

Yes. You can do easily.

Please consider the example below using GetWindowControls(cForm) user defined function.

Code: Select all

# include "minigui.ch"

function main

define window sample at 0,0 width 800 height 600 main
   define label label1
      row 10
      col 10
      width 100
      value "Label 1"
   end  label
   define textbox text1
      row 10
      col 110
      width 120
      value "Sample Text Box 1"
   end textbox
   define label label2
      row 40
      col 10
      width 100
      value "Label 2"
   end  label
   define textbox text2
      row 40
      col 110
      width 120
      value "Sample Text Box 2"
   end textbox
   define label label3
      row 70
      col 10
      width 100
      value "Label 3"
   end  label
   define textbox text3
      row 70
      col 110
      width 120
      value "Sample Text Box 3"
   end textbox
   define button action1
      row 100
      col 10
      width 100
      caption "Press here"
      action dolisting()
   end button
   define listbox list1
      row 130
      col 10
      width 200
      height 200
   end listbox
end window
sample.center
sample.activate
return nil


function dolisting
local aControls := GetWindowControls("sample")
local i := 0
sample.list1.deleteallitems()
for i := 1 to len(aControls)
   sample.list1.additem(aControls[i])
next i
if sample.list1.itemcount > 0
   sample.list1.value := 1
endif
return nil


function GetWindowControls(cForm)
local aControlList := {}
local i := 0
for i := 1 to len(_HMG_SYSDATA[4])
   if _HMG_SYSDATA[4,i] == GetFormHandle(cForm)
      aadd(aControlList,_HMG_SYSDATA [  2,i])
   endif
next i
return aclone(aControlList)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: List of all defined controls in a form

Post by l3whmg »

Hi Rathinagiri,
many, many thanks: I've used your information :mrgreen: .
Every day I discover :o the capabilities of MiniGui.
Bye
Luigi from Italy
www.L3W.it
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: List of all defined controls in a form

Post by l3whmg »

Hi Rathinagiri,
I compiled and tested your program and it works fine. I applied your suggestion to my program, using the "setProperty", but I found some anomaly; in the vector, which should contain the names of the active controls, there are some invalid entries, please, can you compile the source that I've posted and tell me if you have the same like me?

A) select the "Menu" and then " GetControl" on the main menu: three times in succession, the message returns Empty values and then (correctly) "lb_ prgcodice " and "prgcodice";

B) select the "Modal" and then "TestWindow" on the main menu and then the " GetControl", I get this sequence of messages: "StatusTimer", "StatusBar", "toolbar1", "bt_exit", Empty, "bt_save" , Empty, "lb_prgcodice", "prgcodice";

There are a lot of unused functions, but this source is a little "skeleton" of my sorurces.
I made mistakes? Have you the same?

Many thanks in advance
Attachments
mytest.zip
simple source
(969 Bytes) Downloaded 498 times
Luigi from Italy
www.L3W.it
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: List of all defined controls in a form

Post by Rathinagiri »

Hi Luigi,

You didn't make any mistakes. I had made. :)

For menu items and toolbar separators, we don't have names. But, they are also controls.

Now please consider this function.

Code: Select all

STATIC FUNCTION GetWindowControls(cForm)
local aControlList := {}
local i := 0
for i := 1 to len(_HMG_SYSDATA[4])
   if _HMG_SYSDATA[4,i] == GetFormHandle(cForm)
      if len(alltrim(_HMG_SYSDATA [  2,i])) > 0
         aadd(aControlList,_HMG_SYSDATA [  2,i])
      endif   
   endif
next i
for i := 1 to len(aControlList)
msgstop(aControlList[i])
next i
RETURN NIL
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: List of all defined controls in a form

Post by l3whmg »

Hi,
waiting your answer, I do the same :mrgreen:
Luigi from Italy
www.L3W.it
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: List of all defined controls in a form

Post by Rathinagiri »

Wise men think alike. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply