Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@Mike Kaganski has correctly provided the answer (first line in answer) to the question on the difference between ThisComponent and ThisDatabaseDocument with the provided link. However, it seems, based upon further comments, the context of the answer was not fully understood and other misleading, and totally incorrect, comments were made.

The link specifies for ThisDatabaseDocument it is '...only used from a Basic code which is embedded in a Base document.' Now that may not be clear if you do not read it carefully! The code needs to reside in the xxx.odb macro area and NOT in the MyMacros area.

Starting backwards from a form, ThisComponent refers to the form. ThisComponent.Parent refers to the xxx.odb it resides in and ThisComponent.Parent.Parent refers to StarDesktop. ThisDatabaseDocument refers to the xxx.odb and is equal to ThisComponent.Parent.

At the main screen of an xxx.odb, ThisComponent and ThisDatabaseDocument refer to the same thing - the xxx.odb.

Now where the macro code is executed from is another key in usage. You will have code in the document or in MyMacros. With the code in the document the above is true for form and main screen because it is within a database document. If the code resides in MyMacros, it is in StarDesktop. ThisComponent works because it reflects the current document. However, ThisDatabaseDocument will not work because there is no database at the StarDesktop level.

It must be noted, ThisComponent and ThisDatabaseDocument in no way have anything to do with what type of database is being accessed. The above applies to embedded, split and external DB's. This is true whether MySQL on Mint or MariaDB on Debian. They react the same.

Finally, this can all be proven by simply running MRI using the various scenarios presented.