Issue 110324 - Macro assigned to "Before updating of the record" event in the Form control, executes twice
Summary: Macro assigned to "Before updating of the record" event in the Form control, ...
Alias: None
Product: Base
Classification: Application
Component: code (show other issues)
Version: OOO320m9
Hardware: PC Windows XP
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
Depends on:
Reported: 2010-03-22 22:33 UTC by rackham
Modified: 2013-01-29 21:59 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---

fichier Clients (19.00 KB, application/vnd.sun.xml.base)
2010-03-22 22:34 UTC, rackham
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description rackham 2010-03-22 22:33:49 UTC
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 +
End Sub
Comment 1 rackham 2010-03-22 22:34:19 UTC
Created attachment 68494 [details]
fichier Clients
Comment 2 Frank Schönheit 2010-03-23 09:36:35 UTC
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.
Comment 3 Frank Schönheit 2010-03-23 09:36:59 UTC
(... and bail out of the function in exactly one of the two cases)
Comment 4 rackham 2010-03-24 19:29:30 UTC
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
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 ?
Comment 5 Frank Schönheit 2010-03-24 19:49:12 UTC
uhm, my apologies, "css" was just a shortcut for "". So, you need to
check for "".

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>, "" )
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.