[Solved] Programmatically changed data in formctrl not saved

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
joergschulz
Posts: 3
Joined: Tue Apr 08, 2008 10:34 am

[Solved] Programmatically changed data in formctrl not saved

Post by joergschulz »

Hello,

I have a OO-Base form under Linux with data bound controls (to reproduce create a simple table with Base and use the wizard to create the form).
I have manually added a combobox (not bound to a table column) and I want to change the data in one of the bound controls depending on data
selected in that combobox. (Basic sample attached) This works so far. But when I go to the next record and then back I can see that the data in
the bound control was not saved. Also when I change the bound control via the combobox I can see that the record is not marked as modified (the
"save record" symbol is disabled). This is not the case when I change the data in the bound control directly.

The docs say that you have to "actively commit" ?!?
> http://wiki.services.openoffice.org/wik ... g_Controls

I'm trying now for hours, but the API docs are somewhat confusing (at least for the unexpirienced user like me) (as my head is now :?)

Code: Select all

Sub performedWhenComboBoxChanges
        dim doc     as object
        dim form    as object
        dim ctl_cb  as object
        dim ctl_tf  as object

        doc     = stardesktop.currentcomponent
        form    = doc.drawpage.forms(0)
        ctl_cb  = form.getbyname("ComboBox")
        ctl_tf  = form.getbyname("TextField")

        if ctl_cb.text="foo" then
                ctl_tf.text="0"
        elseif ctl_cb.text="bar" then
                ctl_tf.text="1"
        end if

        rem with this the "save record" is activated but OO crashes
        rem form.setPropertyValue("IsModified", True)

        rem this doesnt work either
        rem ctl_tf.commit()
End Sub
Last edited by joergschulz on Tue Apr 08, 2008 9:41 pm, edited 2 times in total.
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: programmatically changed data in form control not saved

Post by DrewJensen »

Howdy joergschulz,

When you set data aware controls via macro code you need to wary of not doing so in a way that fails to fire the update to the underlying ( bound ) data column. In other words some properties of the controls will do this and some won't.

But - there is another way that will work 100% of the time and IMO is preferred. Set the data directly to the bound data column, the control UI will always be updated to reflect the change and the row modification flag will always be set accordingly.

The change for your example code then is:

Code: Select all

Sub performedWhenComboBoxChanges
        dim doc     as object
        dim form    as object
        dim ctl_cb  as object
        dim ctl_tf  as object

        doc     = stardesktop.currentcomponent
        form    = doc.drawpage.forms(0)
        ctl_cb  = form.getbyname("ComboBox")
        ctl_tf  = form.getbyname("TextField")

        if ctl_cb.text="foo" then
                ctl_tf.BoundField.updateString( "0" )
        elseif ctl_cb.text="bar" then
                ctl_tf.BoundField.updateString( "1" )
        end if

        rem with this the "save record" is activated but OO crashes
        rem form.setPropertyValue("IsModified", True)

        rem this doesnt work either
        rem ctl_tf.commit()
End Sub
Both Column and Row interfaces support the updateXXXX functions. You will find a list of these at:
http://api.openoffice.org/docs/common/r ... pdate.html

HTH

Drew
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
joergschulz
Posts: 3
Joined: Tue Apr 08, 2008 10:34 am

Re: programmatically changed data in form control not saved

Post by joergschulz »

That's it. Thank you very much.
Post Reply