Experimental macro features: How to determine object types?

classic Classic list List threaded Threaded
11 messages Options
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Experimental macro features: How to determine object types?

When using the experimental features in Basic I can declare thing in a more
specific way, for instance:

*Dim SomeSheet As com.sun.star.sheet.XSpreadsheet*
Without the experimental features enabled, I had to write this instead:
*Dim SomeSheet As Object*

Is there a way to find out for sure what type some object is supposed to be?
For instance, if I use Object instead and then look at it with XRay, in the
field just above the big field with all the
properties/methods/services/etc, it says *com.sun.star.sheet.XSpreadsheet*,
so that could be a clue, but it doesn't seem to always be usable.
For instance, when declaring a range, XRay says
*com.sun.star.table.XCellRange*, but declaring it like that won't work.
*com.sun.star.sheet.XSheetCellRange* will. How can I figure this out?

At the moment I'm struggling with a search descriptor. XRay says
*com.sun.star.util.XSearchDescriptor*, but that only throws an error at
*SomeRange.createSearchDescriptor()*.

In case anyone wonders why I'm not just declaring it as *Object*, the
answer is because I want to learn these experimental features. I'm not
solving some kind of problem with it at the moment, just trying to learn
about it, which is hard since I can't find any examples, since everybody
declare everything as *Object* and *Variant*…

I'm obviously looking at this the completely wrong way. Is anyone able to
point me in the right direction somehow?
I'm not a coder, so pointing me to the source code is meaningless. I
wouldn't understand anything of it, or at least not quickly enough to not
just give up.


Kind regards

Johnny Rosenberg

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Mauricio Baeza-4 Mauricio Baeza-4
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?


On Mon, 14 Oct 2019 21:02:10 +0200, Johnny Rosenberg <[hidden email]> wrote:

> When using the experimental features in Basic I can declare thing in a more
> specific way, for instance:
>
> *Dim SomeSheet As com.sun.star.sheet.XSpreadsheet*
> Without the experimental features enabled, I had to write this instead:
> *Dim SomeSheet As Object*
>
> Is there a way to find out for sure what type some object is supposed to be?
> For instance, if I use Object instead and then look at it with XRay, in the
> field just above the big field with all the
> properties/methods/services/etc, it says *com.sun.star.sheet.XSpreadsheet*,
> so that could be a clue, but it doesn't seem to always be usable.
> For instance, when declaring a range, XRay says
> *com.sun.star.table.XCellRange*, but declaring it like that won't work.
> *com.sun.star.sheet.XSheetCellRange* will. How can I figure this out?
>
> At the moment I'm struggling with a search descriptor. XRay says
> *com.sun.star.util.XSearchDescriptor*, but that only throws an error at
> *SomeRange.createSearchDescriptor()*.
>
> In case anyone wonders why I'm not just declaring it as *Object*, the
> answer is because I want to learn these experimental features. I'm not
> solving some kind of problem with it at the moment, just trying to learn
> about it, which is hard since I can't find any examples, since everybody
> declare everything as *Object* and *Variant*…
>
> I'm obviously looking at this the completely wrong way. Is anyone able to
> point me in the right direction somehow?
> I'm not a coder, so pointing me to the source code is meaningless. I
> wouldn't understand anything of it, or at least not quickly enough to not
> just give up.


For use a type variable, this type should be "exposed" in the core, by example:

Dim s As String
Dim SomeSheet As com.sun.star.sheet.XSpreadsheet

But, if the type it's not present in core, you always get: "Unknown data", for example:

Dim sd As com.sun.start.util.SearchDescriptor

For this cases, we used Object.

Now, some objects, only can be instance from other objects, like SearchDescriptor

Dim sd As Object

        doc = ThisComponent
        sd = doc.createSearchDescriptor()

I hope clarify your question, and I hope have understand your question.


Best regards




--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
sberg sberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

In reply to this post by Johnny Rosenberg
On 14/10/2019 21:02, Johnny Rosenberg wrote:

> When using the experimental features in Basic I can declare thing in a more
> specific way, for instance:
>
> *Dim SomeSheet As com.sun.star.sheet.XSpreadsheet*
> Without the experimental features enabled, I had to write this instead:
> *Dim SomeSheet As Object*
>
> Is there a way to find out for sure what type some object is supposed to be?
> For instance, if I use Object instead and then look at it with XRay, in the
> field just above the big field with all the
> properties/methods/services/etc, it says *com.sun.star.sheet.XSpreadsheet*,
> so that could be a clue, but it doesn't seem to always be usable.
> For instance, when declaring a range, XRay says
> *com.sun.star.table.XCellRange*, but declaring it like that won't work.
> *com.sun.star.sheet.XSheetCellRange* will. How can I figure this out?

(I have no idea what information that XRay tool prints, but:)  A UNO
object can implement multiple unrelated interfaces, and those interfaces
in turn can each derive from (multiple) other interfaces.  If you look
at the UNO API documentation
(<https://api.libreoffice.org/docs/idl/ref/index.html>, or the udkapi
and offapi modules in the core git source repo), you see that
css.sheet.XSheetCellRange is derived from css.table.XCellRange.  The
former adds one additional method, getSpreadsheet, so if you want to
call that method you need to dim your var as the former, otherwise it
suffices to dim it as the latter.

> At the moment I'm struggling with a search descriptor. XRay says
> *com.sun.star.util.XSearchDescriptor*, but that only throws an error at
> *SomeRange.createSearchDescriptor()*.

If you search for "createSearchDescriptor", there's css.util.XSearchable
that has a method of that name, so you probably have an object at hand
that implements that interface, and to hold that object you need a var
that is dim'ed accordingly.


--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

Aaaaaaaa! Sorry, Stephan Bergmann! I accidentally replied to you, while my
intention was to reply to the list.
Here it is, this time to the list, and this time with further comments at
the end:

Den fre 18 okt. 2019 kl 20:03 skrev Johnny Rosenberg <[hidden email]
>:

> Den tis 15 okt. 2019 kl 08:53 skrev Stephan Bergmann <[hidden email]
> >:
>
>> On 14/10/2019 21:02, Johnny Rosenberg wrote:
>> > When using the experimental features in Basic I can declare thing in a
>> more
>> > specific way, for instance:
>> >
>> > *Dim SomeSheet As com.sun.star.sheet.XSpreadsheet*
>> > Without the experimental features enabled, I had to write this instead:
>> > *Dim SomeSheet As Object*
>> >
>> > Is there a way to find out for sure what type some object is supposed
>> to be?
>> > For instance, if I use Object instead and then look at it with XRay, in
>> the
>> > field just above the big field with all the
>> > properties/methods/services/etc, it says
>> *com.sun.star.sheet.XSpreadsheet*,
>> > so that could be a clue, but it doesn't seem to always be usable.
>> > For instance, when declaring a range, XRay says
>> > *com.sun.star.table.XCellRange*, but declaring it like that won't work.
>> > *com.sun.star.sheet.XSheetCellRange* will. How can I figure this out?
>>
>> (I have no idea what information that XRay tool prints, but:)  A UNO
>> object can implement multiple unrelated interfaces, and those interfaces
>> in turn can each derive from (multiple) other interfaces.  If you look
>> at the UNO API documentation
>> (<https://api.libreoffice.org/docs/idl/ref/index.html>, or the udkapi
>> and offapi modules in the core git source repo), you see that
>> css.sheet.XSheetCellRange is derived from css.table.XCellRange.  The
>> former adds one additional method, getSpreadsheet, so if you want to
>> call that method you need to dim your var as the former, otherwise it
>> suffices to dim it as the latter.
>>
>> > At the moment I'm struggling with a search descriptor. XRay says
>> > *com.sun.star.util.XSearchDescriptor*, but that only throws an error at
>> > *SomeRange.createSearchDescriptor()*.
>>
>> If you search for "createSearchDescriptor", there's css.util.XSearchable
>> that has a method of that name, so you probably have an object at hand
>> that implements that interface, and to hold that object you need a var
>> that is dim'ed accordingly.
>>
>
> This is what I don't really understand, I think.
> From
> https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XSearchable.html#a5e7b729c2d45dea6fa517b96e4e3feea
> :
> com::sun::star::util::XSearchDescriptor
> <https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XSearchDescriptor.html>
> createSearchDescriptor (
> )
>  creates a SearchDescriptor
> <https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1util_1_1SearchDescriptor.html>
> which contains properties that specify a search in this container
>
> It seems like Dim as com.sun.star.util.XSearchDescriptor should do it (and
> both xray and mri describe them as such when Dim as Object, right after the
> oRange.createSearchDescriptor() line).
>
> I'm obviously approaching this the wrong way. Or I totally misunderstand
> what ”and to hold that object you need a var that is dim'ed accordingly”
> actually means.
>
>
I looked a little more into it and I finally got it to work. I'm not sure I
still understand this, but this works:



*Private Function ItemFound(sItem As string, _   oRange As
com.sun.star.sheet.XSheetCellRange) As Boolean Dim oDescriptor As
com.sun.star.util.XReplaceDescriptor
oDescriptor=oRange.createSearchDescriptor()*
*⁝*
*⁝*
*End Function*

So the answer to my question seems to be
”com.sun.star.util.XReplaceDescriptor”. Exactly why is a little blurry to
me at the moment.


Kind regards

Johnny Rosenberg

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
sberg sberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

On 18/10/2019 20:16, Johnny Rosenberg wrote:

> *Private Function ItemFound(sItem As string, _   oRange As
> com.sun.star.sheet.XSheetCellRange) As Boolean Dim oDescriptor As
> com.sun.star.util.XReplaceDescriptor
> oDescriptor=oRange.createSearchDescriptor()*
> *⁝*
> *⁝*
> *End Function*
>
> So the answer to my question seems to be
> ”com.sun.star.util.XReplaceDescriptor”. Exactly why is a little blurry to
> me at the moment.

css.util.XReplaceDescriptor is derived from css.util.XSearchDescriptor.
I assume that what dim'ing you need should depend on what you do with
oDescriptor in the part you elided:  If you only call
XSearchDescriptor-methods on it, then dim as XSearchDescriptor should
suffice.  If you call any of the XReplaceDescriptor-only methods
(getting/setting the ReplaceString), then you need to dim as
XReplaceDescriptor.


--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

Den mån 21 okt. 2019 kl 12:53 skrev Stephan Bergmann <[hidden email]>:

> On 18/10/2019 20:16, Johnny Rosenberg wrote:
> > *Private Function ItemFound(sItem As string, _   oRange As
> > com.sun.star.sheet.XSheetCellRange) As Boolean Dim oDescriptor As
> > com.sun.star.util.XReplaceDescriptor
> > oDescriptor=oRange.createSearchDescriptor()*
> > *⁝*
> > *⁝*
> > *End Function*
> >
> > So the answer to my question seems to be
> > ”com.sun.star.util.XReplaceDescriptor”. Exactly why is a little blurry to
> > me at the moment.
>
> css.util.XReplaceDescriptor is derived from css.util.XSearchDescriptor.
> I assume that what dim'ing you need should depend on what you do with
> oDescriptor in the part you elided:  If you only call
> XSearchDescriptor-methods on it, then dim as XSearchDescriptor should
> suffice.  If you call any of the XReplaceDescriptor-only methods
> (getting/setting the ReplaceString), then you need to dim as
> XReplaceDescriptor.
>
> But in that case, why did the error message happen at the
”oDescriptor=oRange.createSearchDescriptor()” line? I hadn't started to use
it yet…


Kind regards

Johnny Rosenberg

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
sberg sberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

On 21/10/2019 21:43, Johnny Rosenberg wrote:

> Den mån 21 okt. 2019 kl 12:53 skrev Stephan Bergmann <[hidden email]>:
>> On 18/10/2019 20:16, Johnny Rosenberg wrote:
>>> *Private Function ItemFound(sItem As string, _   oRange As
>>> com.sun.star.sheet.XSheetCellRange) As Boolean Dim oDescriptor As
>>> com.sun.star.util.XReplaceDescriptor
>>> oDescriptor=oRange.createSearchDescriptor()*
>>> *⁝*
>>> *⁝*
>>> *End Function*
>>>
>>> So the answer to my question seems to be
>>> ”com.sun.star.util.XReplaceDescriptor”. Exactly why is a little blurry to
>>> me at the moment.
>>
>> css.util.XReplaceDescriptor is derived from css.util.XSearchDescriptor.
>> I assume that what dim'ing you need should depend on what you do with
>> oDescriptor in the part you elided:  If you only call
>> XSearchDescriptor-methods on it, then dim as XSearchDescriptor should
>> suffice.  If you call any of the XReplaceDescriptor-only methods
>> (getting/setting the ReplaceString), then you need to dim as
>> XReplaceDescriptor.
>>
> But in that case, why did the error message happen at the
> ”oDescriptor=oRange.createSearchDescriptor()” line? I hadn't started to use
> it yet…

So what /is/ the exact error message?


--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

Den tis 22 okt. 2019 kl 09:00 skrev Stephan Bergmann <[hidden email]>:

> On 21/10/2019 21:43, Johnny Rosenberg wrote:
> > Den mån 21 okt. 2019 kl 12:53 skrev Stephan Bergmann <
> [hidden email]>:
> >> On 18/10/2019 20:16, Johnny Rosenberg wrote:
> >>> *Private Function ItemFound(sItem As string, _   oRange As
> >>> com.sun.star.sheet.XSheetCellRange) As Boolean Dim oDescriptor As
> >>> com.sun.star.util.XReplaceDescriptor
> >>> oDescriptor=oRange.createSearchDescriptor()*
> >>> *⁝*
> >>> *⁝*
> >>> *End Function*
> >>>
> >>> So the answer to my question seems to be
> >>> ”com.sun.star.util.XReplaceDescriptor”. Exactly why is a little blurry
> to
> >>> me at the moment.
> >>
> >> css.util.XReplaceDescriptor is derived from css.util.XSearchDescriptor.
> >> I assume that what dim'ing you need should depend on what you do with
> >> oDescriptor in the part you elided:  If you only call
> >> XSearchDescriptor-methods on it, then dim as XSearchDescriptor should
> >> suffice.  If you call any of the XReplaceDescriptor-only methods
> >> (getting/setting the ReplaceString), then you need to dim as
> >> XReplaceDescriptor.
> >>
> > But in that case, why did the error message happen at the
> > ”oDescriptor=oRange.createSearchDescriptor()” line? I hadn't started to
> use
> > it yet…
>
> So what /is/ the exact error message?
>
> That's strange. I was convinced that I already said that, but I can't find
it in the thread, so maybe I just didn't.

The exact message is:
”Object not accessible.
Invalid use of an object.”

If I change the Dim statement from ”Dim oDescriptor As
com.sun.star.util.XSearchDescriptor” to ”Dim oDescriptor As
com.sun.star.util.XReplaceDescriptor”, the error message doesn't appear and
everything seems to work.

Example code for testing this:





*Sub Test    Dim oRange As com.sun.star.sheet.XSheetCellRange
oRange=ThisComponent.getSheets().getByIndex(0).getCellRangeByPosition(0,0,10,10)
  Dim oDescriptor As com.sun.star.util.XSearchDescriptor
oDescriptor=oRange.createSearchDescriptor() ' Gives an error message.End
Sub*






*Sub Test    Dim oRange As com.sun.star.sheet.XSheetCellRange
oRange=ThisComponent.getSheets().getByIndex(0).getCellRangeByPosition(0,0,10,10)
Dim oDescriptor As com.sun.star.util.XReplaceDescriptor
oDescriptor=oRange.createSearchDescriptor() ' Works fine.End Sub*

I just think it's a little funny: I want to create a search descriptor, but
”declaring” it as such doesn't work, I need to ”declare” it as a replace
descriptor. It's a little hard to take those things in. :)


Kind regards

Johnny Rosenberg

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

Den tis 22 okt. 2019 kl 14:32 skrev Stephan Bergmann <[hidden email]>:

> On 22/10/2019 14:23, Johnny Rosenberg wrote:
> > *Sub Test    Dim oRange As com.sun.star.sheet.XSheetCellRange
> >
> oRange=ThisComponent.getSheets().getByIndex(0).getCellRangeByPosition(0,0,10,10)
> >    Dim oDescriptor As com.sun.star.util.XSearchDescriptor
> > oDescriptor=oRange.createSearchDescriptor() ' Gives an error message.End
> > Sub*
>
> And how do you enable "the experimental features in Basic"?  If I have a
> working reproducer, I can take a look at why things behave oddly.
>

Two steps:
1. Tools ⇨ Options… ⇨ ▼ LibreOffice ⇨ Advanced ⇨ ☒ Enable experimental
features (may be unstable)
2. Tools ⇨ Options… ⇨ ▼ LibreOffice ⇨ Basic IDE ⇨ ☒ Use extended types


Kind regards

Johnny Rosenberg

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
sberg sberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

On 22/10/2019 14:40, Johnny Rosenberg wrote:

> Den tis 22 okt. 2019 kl 14:32 skrev Stephan Bergmann
> <[hidden email] <mailto:[hidden email]>>:
>     On 22/10/2019 14:23, Johnny Rosenberg wrote:
>      > *Sub Test    Dim oRange As com.sun.star.sheet.XSheetCellRange
>      >
>     oRange=ThisComponent.getSheets().getByIndex(0).getCellRangeByPosition(0,0,10,10)
>      >    Dim oDescriptor As com.sun.star.util.XSearchDescriptor
>      > oDescriptor=oRange.createSearchDescriptor() ' Gives an error
>     message.End
>      > Sub*
>
>     And how do you enable "the experimental features in Basic"?  If I
>     have a
>     working reproducer, I can take a look at why things behave oddly.

<https://gerrit.libreoffice.org/#/c/81386/> "In checkUnoObjectType,
check for derived-from types too" should fix it


--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
sberg sberg
Reply | Threaded
Open this post in threaded view
|

Re: Experimental macro features: How to determine object types?

In reply to this post by sberg
On 21/10/2019 12:53, Stephan Bergmann wrote:

> On 18/10/2019 20:16, Johnny Rosenberg wrote:
>> *Private Function ItemFound(sItem As string, _   oRange As
>> com.sun.star.sheet.XSheetCellRange) As Boolean Dim oDescriptor As
>> com.sun.star.util.XReplaceDescriptor
>> oDescriptor=oRange.createSearchDescriptor()*
>> *⁝*
>> *⁝*
>> *End Function*
>>
>> So the answer to my question seems to be
>> ”com.sun.star.util.XReplaceDescriptor”. Exactly why is a little blurry to
>> me at the moment.
>
> css.util.XReplaceDescriptor is derived from css.util.XSearchDescriptor.
> I assume that what dim'ing you need should depend on what you do with
> oDescriptor in the part you elided:  If you only call
> XSearchDescriptor-methods on it, then dim as XSearchDescriptor should
> suffice.  If you call any of the XReplaceDescriptor-only methods
> (getting/setting the ReplaceString), then you need to dim as
> XReplaceDescriptor.

Turns out I assumed wrongly there about how LO Basic behaves.  In the
true spirit of dynamically typed languages, you can apparently call any
method actually supported by the object, regardless of the "dim as" type
of the variable that holds the object.  (Only when assigning the object
to the variable are types checked to match---and were checked in an
inferior way, see my other mail announcing a fix.)


--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy