Sw4   >   Configuration   >   Main Library Startup_Task

Main Library Startup_Task

The main library Startup_Task is the control center of your StudioWorks application.

When opening a StudioWorks application, the main library startup task $construct method has 2 important jobs to complete before anything can happen:

  1. Open the studioworks folder libraries.

    Without the StudioWorks core libraries we are missing the key object classes and any class which is subclassed from a StudioWorks library is missing its superclass.
  2. Initialize the error handler object which is instantiated by the startup task variable, errhndlr.

    StudioWorks code depends the error handler for logging and communicating errors to the user.

Once the StudioWorks libraries are open and the error handler has been initialized the rest of the code can execute normally.

The oOpenLibraries object class is used by the main library Startup_Task to open the StudioWorks core libraries. The oOpenLibraries object class must be copied from swBase4 to the main library.

There is a problem during startup with handling errors:

  1. The oPaths object can not log errors to the error handler until the StudioWorks core libraries have been opened and the error handler has been initialized.
  2. If the error handler hits an error when it is being initialized how does it report the error to the user?

One solution is to open an OK message to notify the user of the error. The problem with this solution is that if the application is being used as an Omnis web app, the OK message will halt the web server app. (not a good thing.)

The solution which we have opted for in StudioWorks is to send the error to the trace log and then open the trace log. This solution is only used for errors that occur during startup before the StudioWorks libraries are open and the error handler has been initialized.

Creating a Key Object Subclass

When you start a new StudioWorks application most of the main library Startup_Task task variables point to object classes in the you main library which are subclass from objects in the StudioWorks core libraries (swBase4, swGui4, swReports,...).

There comes a point in your StudioWorks application development where you will want to add or modify a method in one of the key objects. In order to do that you will need to override an existing method or add your own method to the subclass object in your main library. The following is an example for adding a custom method to the oFunctions object.

  1. F2 Browser > select oFunctions in your main library > F8 Methods.
  2. Add a $testMethod and put a 4GL Breakpoint command in the method.
  3. Programmer Menu > Programmer Test Method... to get to the breakpoint.
  4. Enter the following line of code in the Programmer Test Method

    Do fn.$testMethod()

  5. Double-click the line of code your entered and click the Step In toolbar button. You should now be inside the $testMethod of your subclass of oFunctions.

If you want to change a superclass method, do the following steps.

  1. Override the superclass method in your subclass object.
  2. Enter your own custom code. If possible, and it makes sense, you should begin your custom code with Do inherited returns FlagOK (or Returns Value). That way you still use the superclass method, and then add your own custom functionality to the superclass method.

    ; Sample code if the superclass returns true or false
    Do inherited Returns FlagOK
    If FlagOK
       ; Enter your custom code here
       
    End If
    Quit method FlagOK

    ; Sample code if the superclass returns a value
    Do inherited Returns Value
    If not(isnull(Value))
       ; Enter your custom code here
       
    End If
    Quit method Value