Compile applications

Compile applications and services.

Before you begin:

Run the script file envcomp in the Genero BDL installation directory to make sure that your FGLDIR and PATH are set correctly to run compiler and runtime system tools.

  1. With a text editor, create an application source file called helloapp.4gl .
    In it copy the code shown in the example and save:
    IMPORT FGL fgldialog
    
    MAIN
      OPEN FORM f FROM "helloapp"
      DISPLAY FORM f
    
      MENU "Exit"
        COMMAND "Hello"
          CALL fgl_winmessage("Hello", "Hello World!", "exclamation")
        COMMAND "exit"
          EXIT MENU
      END MENU
    END MAIN
  2. To create the application form, create a file called helloapp.per
    Copy the code shown in the example and save:
    LAYOUT(TEXT="Hello World")
    GRID
    {
        Hello World!
    }
    END
  3. To create a service application, create a file called helloservice.4gl
    Copy the code shown in the example and save:
    IMPORT XML
    IMPORT COM
    
    &define L(s) DISPLAY SFMT("(%1:%2) %3", __FILE__, __LINE__, s)
    &define LF(s) L(SFMT s)
    
    # Query string parameters
    TYPE QSParams DYNAMIC ARRAY OF RECORD
        name STRING,
        value STRING
      END RECORD
    
    MAIN
      DEFINE url,
             qs,
             requestUrl STRING
      DEFINE request com.HTTPServiceRequest
    
      CALL com.WebServiceEngine.Start()
    
      WHILE TRUE
        TRY
          #Retrieve the HTTPServiceRequest object to handle the HTTP request in various FUNCTIONs
          LET request = com.WebServiceEngine.GetHttpServiceRequest(-1)
    
          #Separate the incoming URL from query string
          LET requestUrl = request.readFormEncodedRequest(false)
          CALL splitUrl(requestUrl) RETURNING url, qs
          CALL processRequest(request, requestUrl)
        CATCH
          LF(("Exception %1 - %2", status, SQLCA.SQLERRM))
          L("Got an exception - Exiting")
          EXIT WHILE
        END TRY
      END WHILE
    END MAIN
    
    { Split an url and returns (path, query string) }
    FUNCTION splitUrl(url)
      DEFINE url STRING
      DEFINE i INTEGER
    
      IF url IS NULL THEN
        RETURN NULL, NULL
      END IF
    
      LET i = url.getIndexOf("?",1)
      IF i >= 1 THEN
        RETURN url.subString(1, i - 1), url.subString(i + 1, url.getLength())
      END IF
    
      RETURN url, NULL
    END FUNCTION
    
    FUNCTION processRequest(request, requestUrl)
      DEFINE request com.HTTPServiceRequest,
             requestUrl STRING
    
      LF(("processRequest: %1", requestUrl))
    
      CALL request.sendTextResponse(200, "OK", "Hello World!")
    END FUNCTION
    
  4. Compile the application and service source files (4gl and per).
    Run the commands shown at the command line:
    fglcomp -r -M helloapp.4gl
    fglform -M helloapp.per
    fglcomp -r -M helloservice.4gl
    
    The application and service 42m and 42f files are created.