ScriptForge.Services zerbitzua

The main purpose of the Services module is to provide access to the CreateScriptService method, which can be called in user scripts to instantiate services that are implemented using the ScriptForge framework.

In ScriptForge terminology a service is a collection of methods and properties that can be used for a common purpose. For example, the String service provides methods for manipulating strings whereas the FileSystem service allows for the manipulation of files and folders.

tip

The Services module of the ScriptForge library provides additional methods that are used either internally to register available services or by developers who are interested in extending ScriptForge by creating new services. The only method that is relevant for user scripts is CreateScriptService.


CreateScriptService

This method is used to instantiate a ScriptForge service so it can be called in user scripts.

The returned value is a Basic object or Nothing if an error occurred.

Sintaxia:

svc.CreateScriptService(service: str, [arg0: any] ...): svc

Parametroak:

service: The name of the service identified as a string in the format "library.service":

arg0, ...: A list of arguments required by the invoked service.

If the first argument refers to an event manager, then arg0 is mandatory and must be the UNO object representing the event provided as argument to the user macro.

Adibidea:

Basic lengoaian

    GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
    ' Behin bakarrik egingo da
    Dim svc As Object
    Set svc = CreateScriptService("Array")
    ' "ScriptForge.Array" zerbitzuari edo SF_Array objektuari egiten dio erreferentzia
    Set svc = CreateScriptService("ScriptForge.Dictionary")
    ' Hiztegi huts baten klase-instantzia bat itzultzen du; "ScriptForge." aukerakoa da
    Set svc = CreateScriptService("SFDocuments.Calc")
    ' Lotutako SFDocuments liburutegian inplementatutako Calc zerbitzuari egiten dio erreferentzia
    Set svc = CreateScriptService("Timer", True)
    ' Berehala hasiko den Timer klase-instantzia bat itzultzen du
    Set svc = CreateScriptService("SFDocuments.DocumentEvent", oEvent)
    ' Lotutako SFDocuments liburutegian inplementatutako DocumentEvent zerbitzuari egiten dio erreferentzia
    ' Gertaera abiarazi duen Document klasearen instantzia egiten dio erreferentzia
  
Python lengoaian

    from scriptforge import CreateScriptService
    svc = CreateScriptService("Array")
    svc = CreateScriptService("ScriptForge.Dictionary")
    svc = CreateScriptService("SFDocuments.Calc")
    svc = CreateScriptService("Timer", True)
    svc = CreateScriptService("SFDocuments.DocumentEvent", oEvent)
  

Python scripts support keyword arguments when calling CreateScriptService. The following example illustrates this concept by instantiating the Timer and Document services using keyword arguments.


    from scriptforge import CreateScriptService
    # Timer
    my_timer = CreateScriptService("Timer", start = True)
    # Document
    my_doc = CreateScriptService("Document", windowname = "some_file.ods")
  
tip

To make writing Python scripts more fluid, ScriptForge provides the Basic service which allows Python scripts to call a collection of methods with the same syntax and meaning as their homonymous native Basic functions.


The following example instantiates the Basic service and calls the MsgBox method, which is equivalent to the MsgBox function available in Basic:


    from scriptforge import CreateScriptService
    bas = CreateScriptService("Basic")
    bas.MsgBox("Hello World!")
  
note

Beware that the Basic service has to be instantiated in Python scripts using the CreateScriptService method.


warning

Azpimarraren karaktere bat, "_", aurrizki gisa duten ScriptForge Basic errutina edo identifikatzaile guztiak barneko erabilerarako erreserbatuta daude. Ez dira Basic makroetan edo Python scriptetan erabili behar.