RE: [dev] starbasic variables and type declarations
Dear Christian, -Original Message- From: Christian Junker [mailto:[EMAIL PROTECTED] Sent: maandag 29 augustus 2005 21:22 To: dev@openoffice.org Subject: Re: [dev] starbasic variables and type declarations Sven, 2005/8/29, Victoria, Sven [EMAIL PROTECTED]: 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? I have never actually used Dim x as Object so I have no experience on unexpected results. The Developer's Guide talks about prefering Variant over Object so I just went that way not investigating on that matter. Ok, I have seen most examples (still) using Objects, so I figured you might have some insight info on this, on why it is not good to do so. Doc = StarDesktop.CurrentComponent So Doc is a document ... ok ... but what can I do with a document? [...] Surely there must be more to a document than only these methods? But how do can I find this information from this point on? Sure there is, the thing is that the Starbasic interpreter takes a lot of work away from you, as do other scripting interpreters. The Basic engine actually binds all exported interfaces your referenced object to it (behind the scenes). That's why you don't need to use queryInterface calls that can frequently be seen in Java/C++ code, in order to invoke a method. That the queryInterface() call is hidden is one thing I can only applaud. It would be really nice if on the the api page of OfficeDocument (or XComponent) references to subclasses (or implementations) are included. It has! Click on the Use link that appears for every idl object at the top. At some places the lists are not complete, so if you find an interface that can be accessed from a certain object and its not listed there, just file an issue for it. Ah! that's much better indeed. I guess that the Variant construction is the way to go :( There is nothing sad about it, if you choose well-named identifiers, Starbasic should be one of the easiest programming languages to read (+ understand) in my eyes. hmmm... (here i go again...) autocomplete would make it _really_ easy. I have read that with Java the NetBeans IDE can be set to include autocomplete on UNO objects. From the point of a Java programmer defining everything as Object (Variants) is then a no-no. As for a Basic programmer on the other hand it is indeed easier to define everything as Variant because it is easier careful however the ms office visual basic editor has autocomplete too \careful. You may wonder why I am poised on autocomplete? Editors are better at supplying the information I need rather then me searching for it i.e. I'm lazy. Nevertheless, thanx for the feedback, it was helpful. Best regards, Sven Victoria -- 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]
[dev] starbasic variables and type declarations
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]
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. 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. 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). 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]
Re: [dev] starbasic variables and type declarations
By the way, I just noticed you use the main development mailinglist, please use dev@api.openoffice.org for such topics. 2005/8/29, Victoria, Sven [EMAIL PROTECTED] [...] -- Best Regards Christian Junker - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [dev] starbasic variables and type declarations
-Original Message- From: Christian Junker [mailto:[EMAIL PROTECTED] Sent: maandag 29 augustus 2005 13:40 To: dev@openoffice.org 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]