How do I use a singleton in LibO basic?

classic Classic list List threaded Threaded
4 messages Options
ptoye ptoye
Reply | Threaded
Open this post in threaded view
|

How do I use a singleton in LibO basic?

I want to use one of the API singletons (com.sun.star.util.thePathSettings
since you ask) but I can find nothing in the documentation telling me how to
create the (only) instance so I can get some of the properties.

As I understand singletons, they have a hidden constructor, and some form of
creator method which ensures that only one instance exists. But the
documentation for the singleton does not have any such method. I've tried
various syntactic forms to create one, none of which has worked.

Can some kind soul please put me out of my misery?

I know that I can use PathSettings, but this is deprecated, and I prefer to
be up-to-date.

I'm using LibO 5.4.5.1 if that helps.



-----
Peter
--
Sent from: http://nabble.documentfoundation.org/Users-f1639498.html

--
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/
All messages sent to this list will be publicly archived and cannot be deleted

Peter
Jean-Francois Nifenecker Jean-Francois Nifenecker
Reply | Threaded
Open this post in threaded view
|

Re: How do I use a singleton in LibO basic?

Hi Peter,

an example using the macro expander which is a singleton as well, defined as :
"/singletons/com.sun.star.util.theMacroExpander"

8< -------------------------------------------------------

Dim oContext as Object 'context object
Dim oMacroExpand as Object 'macro expander
Dim Result As String
       
oContext = getProcessServiceManager().DefaultContext
oMacroExpand = oContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander")

Result = oMacroExpand.ExpandMacros("$UNO_USER_PACKAGES_CACHE")

------------------------------------------------------- >8

the above example is working here in this context.

HTH,
--
Jean-Francois Nifenecker, Bordeaux

----- Mail original -----
De: "ptoye" <[hidden email]>
À: [hidden email]
Envoyé: Mercredi 28 Février 2018 12:51:50
Objet: [libreoffice-users] How do I use a singleton in LibO basic?

I want to use one of the API singletons (com.sun.star.util.thePathSettings
since you ask) but I can find nothing in the documentation telling me how to
create the (only) instance so I can get some of the properties.

As I understand singletons, they have a hidden constructor, and some form of
creator method which ensures that only one instance exists. But the
documentation for the singleton does not have any such method. I've tried
various syntactic forms to create one, none of which has worked.

Can some kind soul please put me out of my misery?

I know that I can use PathSettings, but this is deprecated, and I prefer to
be up-to-date.

I'm using LibO 5.4.5.1 if that helps.



-----
Peter
--
Sent from: http://nabble.documentfoundation.org/Users-f1639498.html

--
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/
All messages sent to this list will be publicly archived and cannot be deleted


--
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/
All messages sent to this list will be publicly archived and cannot be deleted
ptoye ptoye
Reply | Threaded
Open this post in threaded view
|

Re: How do I use a singleton in LibO basic?

Thank you so much for this. I had no idea that you had first to get a context
- I hadn't found this in the documentation (but will now have another look).
It's working fine now.



-----
Peter
--
Sent from: http://nabble.documentfoundation.org/Users-f1639498.html

--
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/
All messages sent to this list will be publicly archived and cannot be deleted

Peter
Jean-Francois Nifenecker Jean-Francois Nifenecker
Reply | Threaded
Open this post in threaded view
|

Re: How do I use a singleton in LibO basic?

Le 28/02/2018 à 18:03, ptoye a écrit :
> Thank you so much for this. I had no idea that you had first to get a context
> - I hadn't found this in the documentation (but will now have another look).
> It's working fine now.

I found this completely by chance when looking into this macro expander
thingy. Then when you asked about a singleton I remembered I had met one
once :)

 From the other side of the pond,
--
Jean-Francois Nifenecker, Bordeaux


--
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/
All messages sent to this list will be publicly archived and cannot be deleted