Notifications
Clear all
[Closed] passing variables
Mar 06, 2015 10:39 pm
Long time no see. Hello everyone.
I was curious to know if anyone out there has a lot of experience with sharing data across multiple dialog windows. In my example attached is a simple name/list tool. It does 3 things.
- Click the β+β button to create a group name. (pass a string variable from edit text field to them main dialgo list)
- Double click the list item to rename it (pass a string to the edit textbox to start, then new name is passed back as the new name.
- Stores the names of the groups into a struct.
Overall it seems like a lot of code for doing something so simple. I was curious to know what better ways of doing this are there and how? Using Structs or better functions?
Thank you
John
clearListener()
try (destroyDialog ::rlGroupsManager) Catch()
rollout rlGroupsManager "Groups"
(
struct groupData (name="")
local groupCollection = #()
local indexEdit = 0
fn CompareNames str1 str2 = stricmp str1.name str2.name
button uiCreateGroup "+" width:30 height:30
multilistbox uiGroupsList ""
fn PopulateGroupsList =
(
qSort groupCollection CompareNames
local groupNames = for g in groupCollection collect g.name
uiGroupsList.items = groupNames
)
fn IsUniqueString strArr:#() str:"" =
(
local namesArr = for g in groupCollection collect g.name
for s in namesArr do
(
if (matchPattern s pattern:str ignorecase:true) AND str != "" AND str != " " do
(
return false
)
)
return true
)
fn AppendGroup str:"" =
(
append groupCollection (groupData name:str)
PopulateGroupsList()
)
fn EditGroupName =
(
if index != unsupplied do
(
rollout rlNameInput "Group Name"
(
dotnetcontrol uiName "Textbox" text:"" width:140 pos:[10,10]
on uiName keyUp s e do
(
if not (IsUniqueString strArr:groupCollection str:uiName.text) then
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 255 0 0
)
else
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 0 0 0
if e.KeyCode == e.KeyCode.Enter do
(
groupCollection[indexEdit].name = uiName.text
PopulateGroupsList()
try(DestroyDialog ::rlNameInput)catch()
)
)
if e.KeyCode == e.KeyCode.Escape do
(
try(DestroyDialog ::rlNameInput)catch()
)
)
on rlNameInput open do
(
uiName.text = groupCollection[indexEdit].name
setfocus uiName
uiName.SelectionStart = 0
uiName.SelectionLength = uiName.text.count
)
)
createDialog rlNameInput 160 50 modal:true
)
)
fn CreateGroup =
(
rollout rlNameInput "Group Name"
(
dotnetcontrol uiName "Textbox" text:"" width:140 pos:[10,10]
on uiName keyUp s e do
(
if not (IsUniqueString strArr:groupCollection str:uiName.text) then
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 255 0 0
)
else
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 0 0 0
if e.KeyCode == e.KeyCode.Enter do
(
AppendGroup str:uiName.text
try(DestroyDialog ::rlNameInput)catch()
)
)
if e.KeyCode == e.KeyCode.Escape do
(
try(DestroyDialog ::rlNameInput)catch()
)
)
on rlNameInput open do
(
setfocus uiName
)
)
createDialog rlNameInput 160 50 modal:true
)
on uiCreateGroup pressed do
(
CreateGroup()
)
on uiGroupsList doubleClicked index do
(
if index >= 1 do
(
indexEdit = index
EditGroupName()
)
)
on rlGroupsManager open do
(
PopulateGroupsList()
)
)
createDialog rlGroupsManager
1 Reply
Mar 06, 2015 10:39 pm
You can access local variable of rollout from outside like this.
otherRolVar = myRollout.localvariable
Or⦠you can just use global variable.