LibreOffice Basic get Elements from form

眉间皱痕 提交于 2019-12-12 22:36:01

问题


I'm trying to get value from textfield on the form.

sub Test(oEv)

oForm = oEv.Source.Model.Parent
textBox = oForm.getByName("Description")
MsgBox textBox.Text

end sub

There is an Exception: "Type: com.sun.star.container.NoSuchElementException" on the line "textBox = oForm.getByName". I have a text field with the name "Description" on the same form, where is the button I press to run this macro. What is wrong here?


回答1:


Check that the name is the same case, not description.

Also, use the Form Navigator to determine whether the control is under the form in the hierarchy.

Have you tried using an introspection tool such as MRI or XrayTool to view the properties of oForm? With the tool, expand the form to see if it contains the Description control.

Often in Base, it is better to deal with the form as a recordset rather than reading the controls. Here is some sample code:

Sub ButtonClickHandler(oEvent as Object)
    'com.sun.star.comp.forms.ODatabaseForm
    oForm = oEvent.Source.Model.Parent
    lDescriptionCol = oForm.findColumn("DESCRIPTION")  ' from underlying query or table
    Print(oForm.getString(lDescriptionCol))
    BasicLibraries.LoadLibrary("XrayTool")
    xray(oForm)
End Sub

For more ideas, see https://forum.openoffice.org/en/forum/viewtopic.php?f=39&t=38725.



来源:https://stackoverflow.com/questions/39766432/libreoffice-basic-get-elements-from-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!