Page 1 of 1
List of all defined controls in a form
Posted: Tue Jan 12, 2010 10:42 pm
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?
Re: List of all defined controls in a form
Posted: Tue Jan 12, 2010 11:08 pm
by l3whmg
Hi,
and sorry
: 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
Re: List of all defined controls in a form
Posted: Wed Jan 13, 2010 6:58 am
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)
Re: List of all defined controls in a form
Posted: Wed Jan 13, 2010 4:43 pm
by l3whmg
Hi Rathinagiri,
many, many thanks: I've used your information
.
Every day I discover
the capabilities of MiniGui.
Bye
Re: List of all defined controls in a form
Posted: Thu Jan 14, 2010 8:33 am
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
Re: List of all defined controls in a form
Posted: Thu Jan 14, 2010 11:57 am
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
Re: List of all defined controls in a form
Posted: Thu Jan 14, 2010 2:38 pm
by l3whmg
Hi,
waiting your answer, I do the same
Re: List of all defined controls in a form
Posted: Thu Jan 14, 2010 4:08 pm
by Rathinagiri
Wise men think alike.