> -----Original Message-----
> From: Christian Junker [mailto:[EMAIL PROTECTED]
> Sent: maandag 29 augustus 2005 13:40
> To: [email protected]
> Subject: Re: [dev] starbasic variables and type declarations
> 
> 
> Hi Sven,
> 
> you misunderstand some things. For example the Dim foo as new ... is
> the prefered syntax for declaring foo to be of a certain struct type,
> and *only* of UNO struct types.
> The object as identified in the IDL with the name of
> "com.sun.star.text.TextField" is a service, that can only be
> constructed during runtime by asking the XMultiServiceFactory of the
> document model to create it for you.

Ok

> example:
> <code>
> Sub Main
>  Dim otxtfield as Variant
>  odoc = thisComponent 'currently active document
>  otxtfield = odoc.createInstance("com.sun.star.text.TextField")
> End Sub
> </code>
> 
> Note that I declared otxtfield of type Variant, not of type Object
> because there are some rare situations where it would fail declaring a
> variable of type Object.

? 
Can you give more insight on this matter? 
 
> As about your question - assigning a known control object to a
> variable can easily be done declaring the variable of type Variant
> before, or to not declare it at all.
> Others reading your code will recognize what type a variable has by
> just looking at the variable name (otxtfield is very clear to me).

True, but it does not give me the needed info I need when looking for 
available methods of a certain service. In your example the 
"com.sun.star.text.TextField" is a giveaway but look at this code snip
from the StarOffice Suite Basic Programmers Guide (p. 143),

        Dim Doc As Object
        Dim Sheet As Object
        Dim FirstRow As Object
        Dim FirstCol As Object

        Doc = StarDesktop.CurrentComponent
        Sheet = Doc.Sheets(0)
        FirstCol = Sheet.Columns(0)
        FirstRow = Sheet.Rows(0)

So Doc is a document ... ok ... but what can I do with a document?

In the api refence I see that StarDesktop.CurrentComponent 
returns an instance that implements interface XComponent.
This interface implements supports the following methods

        - dispose()
        - addEventListener()
        - removeEventListener()

Surely there must be more to a document than only these methods?
But how do can I find this information from this point on?

If the declaration would be like 

        Dim Doc As com.sun.star.document.OfficeDocument
        Dim Sheet As ... 

that would help, this assuming Doc can be cast to an
 OfficeDocument (I'm not sure yet)

It would be really nice if on the the api page of OfficeDocument 
(or XComponent) references to subclasses (or implementations) are included.
 

I hope that autocomplete may sometime be implemented in the macro editor,
but you can imagine what will happen if everything has to be declared as 
Variant/Object

I guess that the Variant construction is the way to go :(

> All of this is documented in the Developer's Guide by the 
> way. So have a look at
> http://api.openoffice.org or download the SDK which has new objects -
> presented in 2.0 beta - listed and to some extent documented in its
> IDL reference.
> 
> 
> 2005/8/29, Victoria, Sven <[EMAIL PROTECTED]>:
> > Hi,
> > 
> > I would like to declare a control variable (reference) in 
> StarBasic and assign an existing control to it
> > from an existing dialog like:
> > 
> > Dim textField  As com.sun.star.text.TextField
> > textField = dialog.getControl("txtKlantNr")
> > 
> > Hoewever the error I get here is: "unknown data type 
> com.sun.star.text.TextField" and the code
> > won't run. Declaring with 'as new' like:
> > 
> > Dim textField  As new com.sun.star.text.TextField
> > 
> > generates the following error:
> > 
> > "Object not accessible. Invalid object reference." but the 
> code will run anyway although it won't
> > run as intended.
> > 
> > Declaring the object as Object will give me no errors but I 
> do not want to declare it
> > as an Object since I know for sure it is a 
> com.sun.star.text.TextField. This way it
> > will be easier for me and others to know with which 
> interfaces we are dealing with, and
> > to look these up in the documentation.
> > 
> > Any suggestions?
> > 
> > Regards,
> > Sven
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> 
> 
> -- 
> Best Regards
> Christian Junker
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to