Ask Your Question
0

How do I create an instance of a singleton?

asked 2018-02-27 20:10:41 +0100

ptoye gravatar image

Title says it all, really. I want to get hold of com.sun.star.util.thePathSettings which is defined as a singleton. But the documentation (either on the LO or AOO sites) doesn't seem to have anything about how to use singletons. How do I get hold of it so I can look at the various paths?

Just writing com.sun.star.util.thePathSettings.Template doesn't work, so I obviously have to create the instance before I can get hold of the attribute.

createUNOservice("com.sun.star.util.thePathSettings") doesn't work either.

I'm using LO Basic.

I'm certainly missing something simple, but what is it?

edit retag flag offensive close merge delete

Comments

a similar request for another singleton: tdf#97447

Mike Kaganski gravatar imageMike Kaganski ( 2018-02-27 20:19:41 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2018-02-28 10:34:55 +0100

librebel gravatar image

Hello @ptoye,

Please try the following:

Dim oPS Object
oPS=  GetDefaultContext().getByName( "/singletons/com.sun.star.util.thePathSettings" )
edit flag offensive delete link more

Comments

Brilliant. Thanks. Shame it doesn't seem to be documented anywhere, at least on the LibO or AOO sites.

ptoye gravatar imageptoye ( 2018-03-01 12:38:54 +0100 )edit
0

answered 2018-02-28 04:10:32 +0100

Jim K gravatar image

com.sun.star.util.PathSettings is an ordinary service.

pathSettings = createUnoService("com.sun.star.util.PathSettings")
MsgBox pathSettings.getPropertyValue("Template")
edit flag offensive delete link more

Comments

Thanks. Agreed. But I'm afraid that it doesn't answer the question I asked. PathSettings is deprecated - see https://api.libreoffice.org/docs/idl/...

That's why I asked about thePathSettings https://api.libreoffice.org/docs/idl/...

The question is really about how to create a singleton, not necessarily about this particular one. Hence the title of the thread.

ptoye gravatar imageptoye ( 2018-02-28 10:26:11 +0100 )edit

Good to know, but next time please include this kind of information in the original question. It's important to describe what you've already discovered while researching the problem. See guidelines for asking.

Jim K gravatar imageJim K ( 2018-03-01 14:51:14 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-02-27 20:10:41 +0100

Seen: 59 times

Last updated: Feb 28 '18