Apache OpenOffice (AOO) Bugzilla – Issue 110324
Macro assigned to "Before updating of the record" event in the Form control, executes twice
Last modified: 2013-01-29 21:59:09 UTC
Hi, In Base, the macro assigned to "Before updating of the record" event in the Form control, executes twice. Open "Rackham, Macros.base2.odb" file. Open "Clients" Form. On the 1rst record, change the value in "CAmensuel" field to 10.00. Click on the "Updating record" button in the scrolling bar. The "CAannuel" will change from 0.00 to 20.00. Here is the macro : Sub MajCAannuel dim PysCtrlCAmensuel as object dim PysCtrlCAannuel as object PysCtrlCAmensuel = ThisComponent.DrawPage.Forms.getByName("Clients").getByName("fmtCA mensuel") PysCtrlCAannuel = ThisComponent.DrawPage.Forms.getByName("Clients").getByName("numCA annuel") 'Xray PysCtrlCAmensuel 'Xray PysCtrlCAannuel PysCtrlCAannuel.Value = PysCtrlCAannuel.CurrentValue + PysCtrlCAmensuel.CurrentValue PysCtrlCAannuel.commit End Sub
Created attachment 68494 [details] fichier Clients
This is a known conceptual problem, though I do not know at the moment whether there already is an issue for this. Basically, the workaround is like this: Check the Event.Source object which is passed to the function, and via its supportsService method, check whether it is a database form (css.sdb.component.DataForm) or a form controller.
(... and bail out of the function in exactly one of the two cases)
I've tested the string "css.sdb.component.DataForm", but I can't find it. The method always returns false. By looking at the object within the debuger, I've found "css.form.component.DataForm". Can you confirm to me this is the string I have to use as parameter of the method supportsService ? The solution works very well and is very simple to implement. But, what is going to happen if for some reason the string of the service name changes in a future version of OpenOffice ? Due to the fact, the string is hard-coded in the macro, the database will continue to work without warning or alert. But the test will become useless and the function will be executed twice again. Is it possible to replace the string by a constant, constant which could be included (#include) in the Basic program and which would be under the full control of the project ?
uhm, my apologies, "css" was just a shortcut for "com.sun.star". So, you need to check for "com.sun.star.form.component.DataForm". It is possible, but pretty unlikely, that this string changes in the future (it didn't change the last 10 years, by the way). There's no reasonable way how this string could be provided by OOo itself, sorry. An alternative would be to use hasUnoInterface( <source_object>, "com.sun.star.form.XForm" ) Again, here it is possible, but pretty unlikely, that this changes in the future. Both aspects - the support of a given service, and the presence of a given interface - are part of the published API of OOo, and as such, we always try our best to keep it as stable as possible.