- the error message says
/Users/npalardy/Desktop/Buoy/For Norman/Norm Work In Progress/junktest.bui:31:0: error: class ‘GlobalVars’ has no shared member, constant, nested enum, or nested structure ‘x_MainWindow’
so make x_mainWindow SHARED PUBLIC
In your code you never create an instance of Globals but I suspect the intent is, or was, to create a single shared set of global variables
SHARED PUBLIC means that you do not need to create an instance of the GlobalsVars class for the shared property to exist
- once you do step 1 you will likely get this as an error
/Users/npalardy/Desktop/Buoy/For Norman/Norm Work In Progress/junktest.bui:41:0: error: class ‘btn_ChangeAddress’ has no field ‘target_window’
which is true there’s no such property so comment out the line trying to set it
b.target_window = w ' ✅ Pass the window reference
3)next you’ll get
/Users/npalardy/Desktop/Buoy/For Norman/Norm Work In Progress/junktest.bui:22:0: error: undefined variable ‘Nothing’
because of this line
If GlobalVars.x_MainWindow IsNot Nothing Then
You CAN just use the ? operator so avoid the comparison entirely
GlobalVars.x_MainWindow?.lbl_Address.Text = "Your Address:"
GlobalVars.x_MainWindow?.ta_Address.Text = "Your Address"
see the example in optional_chain.bui
Optional-chain assignment: obj?.Field = value
Desugars to: If obj <> Nil Then obj.Field = value
The assignment is silently skipped when the receiver is Nil.
after these changes this turns into
Public Window MainWindow
Title = "MainWindow"
Frame = (200, 200, 640, 480)
Control Label lbl_Address
Text = "Label"
Frame = (16, 16, 120, 20)
End Control
Control TextArea ta_Address
Text = "TextArea"
Frame = (136, 16, 300, 200)
End Control
End Window
Public Class GlobalVars
Shared Public Property x_MainWindow As MainWindow
End Class
Class btn_ChangeAddress Inherits Button
Handle Action()
GlobalVars.x_MainWindow?.lbl_Address.Text = "Your Address:"
GlobalVars.x_MainWindow?.ta_Address.Text = "Your Address"
End Handle
End Class
Sub Main()
Dim w As New MainWindow()
GlobalVars.x_MainWindow = w
' Set initial values
w.lbl_Address.Text = "My Address:"
w.ta_Address.Text = "My Address"
' Create button and capture window reference
Dim b As New btn_ChangeAddress()
b.Caption = "Change to Address"
b.Move(136, 224, 300, 32)
w.AddSubview(b)
w.Show()
Application.Run()
End Sub