Use cases for SupportsService with Document object

I already told you. But not in case when you already know that it’s a document.

Thank you. Again, I’m not trying to be annoying on purpose, but I have no idea whatsoever what the Frame-Controller-Model paradigm is, so I should probably study this first.

So, just to summarize: The verdict is: Yes, there are use cases when it would be meaningful, for example, to execute the following statement:
.

ThisComponent.supportsService("com.sun.star.sheet.SpreadsheetDocumentSettings")

.
The rationale or explanation for those use cases can be found in Frame-Controller-Model paradigm. I should study and understand this first.
.
Is this the correct understanding?

No. The FCM is related to com.sun.star.document.OfficeDocument. For com.sun.star.sheet.SpreadsheetDocumentSettings, you may simply open the service documentation, and find out, that two different services include it - thus, at least two different object types can implement that service. It is not necessarily a document.

But note, that you expect people here educating you. Ask site is about “how do I …?” type of questions…

To be clear, I don’t expect anything at all, Mike. That’s your interpretation. I came here with my question in the hope that someone might be able to provide some insight, not an expectation that people do my work for me. I also did not know that the type of question I asked is generally not welcome here, as you seem to be implying.

No, I don’t see a problem in these questions. Just not sure if you will get what you want, when a good answer to your questions would take a really big article, and I can only scratch the surface with my replies.

A “how do I” type of question may get a short answer. And in your case, you need to learn a lot, e.g. you wrote “in VBA you deal with objects, methods, properties and events. VBA does not have contracts or guarantees” - but note that it’s not about LibreOffice Basic, either: it’s about UNO, which is the API of LibreOffice, common for all languages talking to it.

On the other hand, the guarantee, or a contract, is a concept common to any programming language. When you read something like “Function Foo: returns Integer” - that is a guarantee, that the language or the library provides. Having read that, you know what to expect, and you don’t need to care if you get an unexpected String as the return value.

Services are a similar guarantee: if an object tells you that it implements a service, you may be sure that it implements all interfaces that the service includes (and also all the interfaces in included services), and also provides all the properties.

Just treat me like a child. :grinning: Seriously. Children have endless questions. You, as the adult, know much more than the child does and you could give a very long, comprehensive answer to the question, but that would just confuse the child. Like a child, I am satisfied with a simplified response for now. As my understanding increases, I hope I will be able to ask better questions.

Yes, now we are getting closer to the root of the problem. I learned to program VBA in a completely different way than any formal education in programming. I learned VBA by having to solve concrete problems in VBA without ever having any formal training in programming. So while I know pretty much everything there is to know about VBA, I know very little about fundamental concepts of programming that are probably no-brainers to you.

ChatGPT is guesswork owned by Microsoft. Why should it ever write correct LibreOffice macros, given that LibreOffice is considered as enemy?
ThisComponent is a convenient StarBasic variable.
In Python: doc = XSCRIPTCONTEXT.getDocument()
Forget VBA. StarBasic is not even similar to VBA. Both Basic dialects talk to completely different APIs. VBA is a fat layer, full of syntactic sugar and convenience features. A VBA method may take this or that with lots of optional arguments, and it may return this or that. UNO is clear and very strict when it comes to argument types and returned data types, which is why it is portable across operating systems and target languages. Yes, it is by far more difficult than VBA, however every UNO object can report everything about itself: [Tutorial] Introduction into object inspection with MRI

While I can certainly see how Microsoft would not have an interest in promoting LibreOffice, the fact remains that I have actually received many useful examples of LibreOffice Basic code from ChatGPT. Be thankful. It saved you from me asking my never-ending questions here. :grinning:

Forget VBA. StarBasic is not even similar to VBA.

Actually, I don’t think that’s true. The syntax and language features of VBA and StarBasic are actually almost identical.

Both Basic dialects talk to completely different APIs.

I think this is essentially correct, although VBA is by no means restricted to talking to the Microsoft Office API. Other programs also come bundled with VBA, such as Corel Draw and Autocad, and the APIs of those programs are quite different. VBA can also talk to any number of APIs and object models using COM references, Declare Function statements and so on.

VBA is a fat layer, full of syntactic sugar and convenience features. A VBA method may take this or that with lots of optional arguments, and it may return this or that. UNO is clear and very strict when it comes to argument types and returned data types, which is why it is portable across operating systems and target languages. Yes, it is by far more difficult than VBA, however every UNO object can report everything about itself

I have two problems with statements like this. First of all, I get a strong feeling that you intensely dislike VBA, and since StarBasic (LibreOffice Basic) is almost identical in syntax and features, you probably don’t like LibreOffice Basic very much either. While that is absolutely your right, you can hardly expect a person like me with decades of experience programming VBA solutions, and later VSTO solutions, to share your views. You also cannot expect people to learn what you consider a real programming language (probably Python), just to program some macros for LibreOffice. I am also convinced that as long as the Document Foundation does not kill LibreOffice Basic, it should be given the same treatment as any other language you can use to write LibreOffice macros. The second problem I see here is that you are comparing VBA to UNO. I do not think this is an accurate comparison because VBA is a language (that is almost identical to LibreOffice Basic) and UNO is an API (that is unlike anything I have ever seen before). :slight_smile:

1 Like