Notifications
Clear all

[Closed] How can I call a button with a variable ?

Hello,

With different buttons of a rollout :

button bu1 “blabla”
button bu2 “bloblo”
etc…

I would like to make liste

ListButton = #(“bu1”,“bu2”,…)

and then being able to do something which would work like this ;

ListButton[1].caption = “Blabla2”

(I would I like to do the same thing with the state of radiobuttons)

Is it possible ? Does anyone know how to do this ?

Thank you in advance
Daniel

5 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

try(destroydialog test_rol) catch()
rollout test_rol "check buttons list"
(
 group "Check Buttons: "
 (
  checkbutton ch1 "" width:170
  checkbutton ch2 "" width:170
  checkbutton ch3 "" width:170
  checkbutton ch4 "" width:170
 )
 button rename "Rename" width:170 offset:[0,4]
 
 local names = #("May", "April", "June", "July")
 local chs = #(ch1,ch2,ch3,ch4) -- it should be pointers to control - NOT NAMES
 
 on rename pressed do
 (
  new = copy names #nomap
  for k=1 to chs.count do 
  (
   id = random 1 new.count
   chs[k].caption = new[id]
   chs[k].state = ((random 0 1) == 0)
   deleteitem new id
  )
 )
 on test_rol open do for k=1 to chs.count do chs[k].caption = names[k]
)
createdialog test_rol width:200 height:170

 
rollout test "TEST"
(
button bu1 "blabla"
button bu2 "bloblo"

button changeName "Change Name" 

local ListButton = (for r in test.controls where classof r == ButtonControl collect r)

on changeName pressed do (ListButton[1].caption = "Blabla2")


)
createdialog test 200



you can use any control type and can also test controls by there names while collecting them in ListButton array.

R

It works. Exactly what I needed. Thank you.

You can also use getProperty on a rollout


 
 rollout roll "Test" (
 	button uiTestBTN "Test"
 	button uiTest2BTN "Test"
 	button uiTest3BTN "Test"
 	
 	function setTitles widgets title = ( 
 		for n in widgets do (getProperty roll n).caption = title 
 	)
 	
 	on uiTestBTN pressed do ( roll.setTitles #( #uiTestBTN, #uiTest2BTN ) "Button 01" )
 	on uiTest2BTN pressed do ( roll.setTitles #( #uiTest2BTN, #uiTest3BTN ) "Button 02" )
 	on uiTest3BTN pressed do ( roll.setTitles #( #uiTestBTN, #uiTest2BTN, #uiTest3BTN ) "Button 03" )
 )
 
 createDialog roll
 
   

Hi,

If you want to loop through all the controls and filter them by type, use the Controls property on the rollout:

for control in rollout.Controls where ClassOf control == ButtonControl do Print control.Name

Light