Słužba ScriptForge.Services

Hłowny zaměr modula Services je, přistup k metodźe CreateScriptService j dispoziciji stajić, kotraž da so we wužiwarskich skriptach wuwołać, zo bychu so słužby instanciěrowali, kotrež so z framworkom ScriptForge implementuja.

W terminologiji ScriptForge je słužba zběrka metodow a kajkosćow, kotrež dadźa so za zhromadny zaměr wužiwać. Słužba String na přikład metody za wobchadźenje ze znamješkowymi rjećazkami k dispoziciji staja, mjeztym zo słužba FileSystem je za wobchadźenje z datajemi a rjadowakami.

Symbol Pokiw

Modul Services biblioteki ScriptForge přidatne metody skići, kotrež so pak internje wužiwaja, zo bychu słužby registrowali, kotrež su k dispoziciji, pak wot wuwiwarjow, kotřiž su na tym zajimowani, ScriptForge přez wutworjenje nowych słužbow rozšěrić. Jenička metoda, kotraž je relewantna za wužiwarske skripty, je CreateScriptService.


CreateScriptService

Tuta metoda so wužiwa, zo by słužbu ScriptForge instanciěrowała, zo by so dała we wužiwarskich skriptach wuwołać.

Wróćena hódnota je objekt Basic abo Nothing, jeli zmylk je nastał.

Syntaksa:

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

Parametry:

service: Mjeno słužby, kotraž so jako znamješkowy rjećazk w formaće "library.service" identifikuje.

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.

Přikład:

W Basic

    GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
    ' To be done once
    Dim svc As Object
    Set svc = CreateScriptService("Array")
    ' Refers to the "ScriptForge.Array" service or SF_Array
    Set svc = CreateScriptService("ScriptForge.Dictionary")
    ' Returns a new empty dictionary class instance; "ScriptForge." is optional
    Set svc = CreateScriptService("SFDocuments.Calc")
    ' Refers to the Calc service, implemented in the associated SFDocuments library
    Set svc = CreateScriptService("Timer", True)
    ' Returns a Timer class instance starting immediately
    Set svc = CreateScriptService("SFDocuments.DocumentEvent", oEvent)
    ' Refers to the DocumentEvent service implemented in the associated SFDocuments library
    ' Returns the instance of the Document class that fired the event
  
W Python

    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")
  
Symbol Pokiw

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!")
  
Symbol za Notica

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


Warnowanski symbol

Wšě rutiny Basic ScriptForge abo identifikatory, kotrež so z podsmužku „_“ započinaja, su za interne wužiwanje wuměnjene. Njejsu za to myslene, so w makrach Basic abo skriptach Python wužiwać.


Prošu podpěrajće nas!

Prošu podpěrajće nas!