I need to create this dialog programatically because it will have a variable number of controls depending on the client. (The naming conventions are sloppy right now because i am in the middle adapting someone else’s code.) The code chokes when the focusGained sub is entered (see below).
I have tried many things but especially of note is: if i change the relevant lines to deal with the textChanged event instead, it all works as expected.
Sub main
Dim dlgmodel As Variant
Dim oComponents As Variant
Dim oDoc As Variant
dlgmodel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
With dlgmodel
.Name = "checkwriter"
.Title = "check writer"
.PositionX = 170
.PositionY = 70
.Width = 190
.Height = 100
.DesktopAsParent = false ' or true, does not affect problem
End With
Dim oModel As Variant
oModel = dlgmodel.createInstance("com.sun.star.awt.UnoControlGroupBoxModel")
omodel.name = "rbgroup"
dlgmodel.insertByName(oModel.Name, oModel)
dim j%
for j = 0 to 3 ' 3 is for example
oModel = dlgmodel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel")
With oModel
.Name = "rb" & j
.PositionX = 10
.PositionY = 6 + j * 15
.Width = 12
.Height = 12
.groupname = "rbgroup"
End With
dlgmodel.insertByName(oModel.Name, oModel)
oModel = dlgmodel.createInstance("com.sun.star.awt.UnoControlEditModel")
with omodel
.Name = "txt" & j
.PositionX = 40
.PositionY = 6 + j * 15
.Width = 40
.Height = 12
end with
dlgmodel.insertByName(oModel.Name, oModel)
next
Dim oDlg As Variant
oDlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
oDlg.setModel(dlgmodel)
Dim oControl As Variant
oListener = CreateUnoListener("txt_", "com.sun.star.awt.XFocusListener")
oControl = oDlg.getControl("txt0") ' testing one single edit control
ocontrol.addFocusListener(oListener)
Dim oWindow As Variant
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
oDlg.createPeer(oWindow, null)
oDlg.execute()
End Sub
'entering focusGained() causes
' "BASIC runtime error. Property or method not found: $(ARG1)."
' after clearing that, the print statement executes.
' ***warning*** without the print statement the dialog will become uncloseable.
sub txt_focusGained(event as object)
print "txt1"
end sub