Message 1 of 4
how to use the same object in each button ?
Not applicable
08-18-2012
03:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello.
In the code below I create two buttons. I wanted to use the same object that I could update and use to setup data in each button. But I hit the wall. If I try to use object already created in my struct, inside button Event, I get:
with this code:
Now if I modify the code:
and try to pass data thru function and then use them in button events, i get:
So, how to correctly pass the same object into each button so I could work with the same data in each ?
In the code below I create two buttons. I wanted to use the same object that I could update and use to setup data in each button. But I hit the wall. If I try to use object already created in my struct, inside button Event, I get:
Runtime error: Struct member access requires instance: _dataContainer <<
with this code:
struct MyContainer
(
public
lockView = true
)
struct TestUI
(
private
text = "hello",
_dataContainer = MyContainer(),
public
fn Create =
(
rollout MainWindow "Test"
(
button GI_btn @" GI " width:100 _height:30 pos:
button Farm_btn @" FARM " width:100 height:30 pos:
/* EVENTS ---------------------------------------- */
on GI_btn pressed do
(
_dataContainer.lockView = true
)
on Farm_btn pressed do
(
messagebox (_dataContainer.lockView as string)
)
)
createDialog MainWindow 200 200
)
)
_ui = TestUI()
_ui.Create()
Now if I modify the code:
struct MyContainer
(
public
lockView = true
)
struct TestUI
(
private
text = "hello",
public
fn Create _dataContainer =
(
rollout MainWindow "Test"
(
button GI_btn @" GI " width:100 _height:30 pos:
button Farm_btn @" FARM " width:100 height:30 pos:
/* EVENTS ---------------------------------------- */
on GI_btn pressed do
(
_dataContainer.lockView = true
)
on Farm_btn pressed do
(
messagebox (_dataContainer.lockView as string)
)
)
createDialog MainWindow 200 200
)
)
_my = MyContainer()
_ui = TestUI()
_ui.Create _my
and try to pass data thru function and then use them in button events, i get:
Compile error: No outer local variable references permitted here: _dataContainer
So, how to correctly pass the same object into each button so I could work with the same data in each ?