Forwarded to the list for a reply -
I am able to display a list of the forms in a database but the next step is to
get all the controls from a specific form / dialog.
I have the following code working
Global sMyMess as String
CONST Message1 = "Message1"
Sub Main
GetControlsInForm
End Sub
Sub GetControlsInForm
Dim Context As Object
Dim DB As Object
Dim FormDoc as Object
Dim FormName as String
Dim Connection As Object
Dim Args(1) As New com.sun.star.beans.PropertyValue
Dim NumControls as Integer
Dim oDoc As Object
Dim oComponents As Object
Dim MyText as String
Context=CreateUnoService("com.sun.star.sdb.DatabaseContext")
DB=Context.getByName("HERBS")
Connection=DB.getConnection("","")
FormDoc=DB.DatabaseDocument.FormDocuments()
MsgBox FormDoc.Name ' this is the names of the forms
MsgBox FormDoc.Count ' this is the number of forms
NumControls = FormDoc.Count()
For i = 0 To NumControls -1
sMyMess = FormDoc(i).Name
if sMyMess = "TestCont" then
GetControlsInTestCont
end if
Next
End Sub
Sub GetControlsInTestCont
msgbox sMyMess
End Sub
Good question - and the terminology here can be a bit confusing.
TIP - You really need to get a runtime object inspector two choices but
I would recommend you start with this one:
X - Ray Tool by Bernard Macelly
http://www.ooomacros.org/dev.php#101416
There is also an object introspection tool at
http://wiki.services.openoffice.org/wiki/Object_Inspector
I would recommend you look at this page:
http://wiki.services.openoffice.org/wiki/Extensions_development_basic
I know you are not creating an "extension" per si, but in reality you
are doing just that - extending the basic functionality of the
application as shipped.
So - database forms where they live and how to get to the controls on
them -
http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/OfficeDatabaseDocument.html
"
specifies a office database document which is a storable document.
These documents contain information about forms, and reports, and
the properties of a data source.
The database document contains no data per default. The following
is stored inside the document:
# Forms
# Reports
# The table settings defined in DataSettings
# The query settings defined in DataSettings
# All properties of the service DataSource
"
So this is the .odb file then.
Forms and Reports as used above both refer to containers, a collection
in other words. Specifically a DocumentContainer:
http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/DocumentContainer.html
So looking at your line of code:
FormDoc=DB.DatabaseDocument.FormDocuments()
FodmDoc is a DocumentContainer, and at this point I should point out
that it is capable of container an element that is another
DocumentContainer, represents a hierarchical container, in the Base UI
an element that is another DocumentContainer is called a Folder.
All pretty common stuff so far or is it..
Look at the next couple lines of your code:
MsgBox FormDoc.Name ' this is the names of the forms
MsgBox FormDoc.Count ' this is the number of forms
FormDoc.name is the name of the Forms Container
FormDoc.Count is the count of elements in the collection at the root of
the hierarchy. That is a very important distinction.
Let's say you actually create some Folders in your Forms section of a
Base file. Maybe 2 folders and each folder has 2 'forms' and there is
also a single form, not in a folder - so the Base forms section might
look like:
Folder1
-- Form2
-- Form3
Folder2
-- Form4
-- Form5
Form1
( It is not just the display that is alphabetized for your local by the
way, as you will see )
What does your code return for
FormDoc=DB.DatabaseDocument.FormDocuments()
FormDoc.Count
Does it return 5, which is the number of forms in your database?
NO!
It returns 3.
FormDoc(0).Name = "Folder1"
FormDoc(1).Name = "Folder2"
FormDoc(2).Name = "Form1"
Quick side note: the container also offers the xNameService, which means
you can ask for an item by name.
So you could use
FormDoc.getByName( "Form1" )
That works.
But you still need to be aware of that possible hierarchy.
FormDoc.getByName( "Form2" ) will fail.
FormDoc.getByName( "Folder1/Form2" ) is correct.
Fine - well without belaboring this here is an example getting all the
documents from a DocumentContainer. The routine uses recursion to fill a
list box with all the names of documents in the container, formatted
properly to be used in a container.GetByname( x ) call later by setting
aIncludeContainerName = TRUE.
It will work equally well for Forms and Reports.
function fillListBox( aListBox as variant,_
aContainer as new
"com.sun.star.comp.dba.ODocumentContainer",_
aIncludeContainerName as boolean,_
Optional aParentName as string ) as boolean
dim cntr as integer
dim tmpString as string
dim ParentName as string
if not isMissing( aParentName ) then
ParentName = aParentName
else
ParentName = ""
end if
for cntr = 0 to aContainer.Count -1
tmpString = ""
if aIncludeContainerName then
tmpString = ParentName & acontainer.Name & "/"
end if
if aContainer.getByIndex( cntr ).ImplementationName =
"com.sun.star.comp.dba.ODocumentContainer" then
fillListBox( aListBox, aContainer.getByIndex( cntr ), True, tmpString )
else
tmpString = tmpString & aContainer.getByIndex( cntr ).Name
aListBox.AddItem( tmpString, aListBox.ItemCount )
end if
next
end function
(TIP - that could of, maybe even should of, been written using an
ENUMERATION, and it might be worth taking the time to make the change as
a good exercise.
For specifics on enumerations and a recap of all this actually see:
http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/Interface_Overview
)
Ok - so now you can get a specific document, but you asked about finding
controls on a form, what does this have to do with that. Well, as you
will see in the next message it is again going to be about containers.
Drew
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]