[Libreoffice-bugs] [Bug 134232] TextBox: the text assigned to the Text property isn't displayed in UI (v6.0.x .. 6.4.4.2)

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Thu Jul 16 21:35:27 UTC 2020


https://bugs.documentfoundation.org/show_bug.cgi?id=134232

TFKane <tufkane at tutanota.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |UNCONFIRMED
     Ever confirmed|1                           |0

--- Comment #3 from TFKane <tufkane at tutanota.com> ---
Hi Xisco,


I made a mistake.


Hoping the following details allows to avoid other users to made the same
mistake.


To make long story short, there are two way to read and update controls
contents (e.g., TextField):

1) read/update controls content immediately before the dialog is shown:

Sub ShowDialog134232
    BasicLibraries.LoadLibrary("Tools")
    oDialog134232 = LoadDialog("Standard", "Dialog134232")
        oText  = oDialog134232.getControl("MyTextBox")
        msgbox "updating <"+oText.Text+"> ... (will succeed)"
        oText.Text = "Bug 134232 ... updated text"
        oDialog134232.Execute()
End Sub


2) read/update controls content on user interaction (e.g. button click):

Sub ButtonClicked_ProperWay(Event as Object)
        Button = Event.Source()
        Context = Button.getContext()
        oText = Context.getControl("MyTextBox")
        msgbox "updating <"+oText.Text+"> ... (will succeed)"
        oText.Text = "it works"
End Sub


To make long story long, keep reading.


MODULE AND DIALOG DESCRIPTION


The attached module (Module134232) and form (Dialog134232) will explain both
the flaw and the proper way to proceed.


Dialog134232 has three controls:

- MyTextBox: a textbox with preassigned text "Bug 134232"

- WrongWayButton: a button labelled with the text "Update Text - Wrong Way"

- ProperWayButton: a button labelled with the text "Update Text - Proper Way"



Module134232 has three subs:

- ShowDialog134232: to show dialog and allow user to interact with it

- ButtonClicked_WrongWay: called on the WrongWayButton button click

- ButtonClicked_ProperWay(Event as Object): called on the ProperWayButton
button click

All subs pops up a message with the current text and the message that the text
is going to be changed



STEP BY STEP USAGE

Load module and dialog in LibreOffice Calc.

Then, choose Tools -> Macros -> Run Macro

"Macro Selector"  dialog will be shown.

Select MyMacros -> Standard -> Module134232 in the "Library" tree on the left
side, then choose ShowDialog134232 in the "Macro Name" list on the right side.
Click Run.

A message box with the text "updating <Bug 134232> .... (will succeed)" will be
shown.
Click "OK".
The message box disappears and the Dialog134232 become visible.
The text in the MyTextBox text field "Bug 134232" has actually been replaced
with "Bug 134232 ... updated text".

Click the "Update Text - Wrong Way" button.
A message box with the text "updating <Bug 134232> .... (will fail)" will be
shown.
Click "Ok".
The message box disappear and the text field remains unchanged.

Click the "Update Text - Proper Way" button.
A message box with the text "updating <Bug 134232 ... updated text> .... (will
succeed)" will be shown.
Click "Ok".
The message box disappear and the text field is replaced with "it works".


CONCLUSIONS

Essentially, my mistake - at least as far as I can understand - was the attempt
to update fields on a button click in this way (ButtonClicked_WrongWay is
assigned to button "Execute action" event):

Sub ButtonClicked_WrongWay
    BasicLibraries.LoadLibrary("Tools")
    oDialog134232 = LoadDialog("Standard", "Dialog134232")
        oText  = oDialog134232.getControl("MyTextBox")
        msgbox "updating <"+oText.Text+"> ... (will fail)"
        oText.Text = "this won't be displayed"
End Sub

The Sub body actually create a new Dialog instance and interact with it,
leaving unchanged the displayed one.


The right way to do this, is:

Sub ButtonClicked_ProperWay(Event as Object)
        Button = Event.Source()
        Context = Button.getContext()
        oText = Context.getControl("MyTextBox")
        msgbox "updating <"+oText.Text+"> ... (will succeed)"
        oText.Text = "it works"
End Sub

However, I was unable to find any documentation that illustrated the above.
Indeed, I had to guess the the "Event as Object" parameter existance.

IMO, the LibreOffice Basic documentation should be integrated with a more
accurate API documentation and possibly many examples. At least, in my
experience.

Hoping this post was helpful.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20200716/44d5d2d2/attachment-0001.htm>


More information about the Libreoffice-bugs mailing list