Events 为什么此libreoffice编辑控件事件处理程序不工作
我需要以编程方式创建此对话框,因为根据客户端的不同,它将具有不同数量的控件。(命名约定现在是草率的,因为我在中间适应别人的代码。)当CoopSuffSub进入时,代码会哽住。 我已经尝试了很多事情,但特别值得注意的是:如果我改变相关的行来处理textChanged事件,那么一切都会按预期进行Events 为什么此libreoffice编辑控件事件处理程序不工作,events,controls,libreoffice,calc,uno,Events,Controls,Libreoffice,Calc,Uno,我需要以编程方式创建此对话框,因为根据客户端的不同,它将具有不同数量的控件。(命名约定现在是草率的,因为我在中间适应别人的代码。)当CoopSuffSub进入时,代码会哽住。 我已经尝试了很多事情,但特别值得注意的是:如果我改变相关的行来处理textChanged事件,那么一切都会按预期进行 Sub main Dim dlgmodel As Variant Dim oComponents As Variant Dim oDoc As Variant dlgmo
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
该接口需要两种方法。您只实现了其中一个,这就是发生错误的原因
要修复此问题,请添加以下内容:
sub txt_focusLost(event as object)
print "txt2"
end sub
但是,您确定需要焦点侦听器吗?正如您通过运行它所看到的,修改后的代码会导致无限循环。焦点通常比较棘手,根据操作系统的不同,其工作方式也不同。通常我使用
textChanged
。解决方案的详细信息和示例
非常好的初始问题,包含重现问题所需的所有代码和信息。但是,可以通过删除代码中不相关的部分(如单选按钮)来改进它。另外,标题太长了,这个问题应该放在最后。缺少focusLost()无疑是问题的主要部分