INIT PROCEDURE

INIT PROCEDURE

Declare an initialization procedure

Syntax

       INIT PROCEDURE <idProcedure> [(<idParam list>)]
          [FIELD <idField list> [IN <idAlias>]]
          [LOCAL <identifier> [[:= <initializer>]]]
          [MEMVAR <identifer list>]
          .
          . <executable statements>
          .
          [RETURN]

Arguments

INIT PROCEDURE declares a procedure that will be executed at program startup.

<idProcedure> is the name of the initialization procedure to declare. Initialization procedure names can be any length, but only the first 10 characters are significant. Names may not begin with an underscore but can contain any combination of characters, numbers, or underscores.

<idParam list> is the declaration of one or more parameter variables. Variables specified in this list are declared local.

FIELD declares a list of identifiers to use as field names whenever encountered. If the IN clause is specified, referring to the declared name includes an implicit reference to the specified alias.

LOCAL declares and, optionally, initializes a list of variables or arrays whose visibility and lifetime is the current procedure.

MEMVAR declares a list of identifiers to use as private or public memory variables or arrays whenever encountered.

RETURN passes control to the next initialization procedure or the first executable routine in the program, if no other initialization procedures are pending.

Description

The INIT PROCEDURE statement declares a procedure that will be executed at program startup. INIT procedures are called prior to the first executable statement in a Clipper application, and are useful for performing common initialization tasks such as reading configuration settings, or opening a communications port.

INIT PROCEDUREs are executed implicitly by Clipper at program startup. The visibility of initialization procedures is restricted to the system; therefore, it is not possible to call an INIT PROCEDURE from a procedure or user-defined function. Each INIT PROCEDURE receives a copy of the DOS command line arguments used to invoke the application.

Control passes from one INIT PROCEDURE to the next until all procedures in the initialization list have been called. Control then passes to the first executable statement in the program.

The ANNOUNCE statement declares a module identifier for a source (.prg) file. Once declared, INIT PROCEDUREs are referenced by this module identifier. An application may use any number of initialization procedures by explicitly REQUESTing their module identifiers.

If an error is raised during system initialization, the system returns to DOS, and pending initialization procedures are not called.

Examples

       .  The following example uses both INIT and EXIT PROCEDUREs to
       save and restore the context of the operating system. You can have
       your program, "Myfile.prg", REQUEST SaveDos:

       ANNOUNCE SaveDos
       #define DOS_SCREEN    1
       #define DOS_ROW       2
       #define DOS_COL       3
       #define DOS_CURSOR    4
       #define DOS_COUNT     4
       STATIC saSaveDos[ SD_COUNT ]
       INIT PROCEDURE dosSave()
          SAVE SCREEN TO saSaveDos[ DOS_SCREEN ]
          saSaveDos[ DOS_ROW ]    := ROW()
          saSaveDos[ DOS_COL ]    := COL()
          saSaveDos[ DOS_CURSOR ] := SETCURSOR()
          RETURN
       EXIT PROCEDURE dosRestore()
          RESTORE SCREEN FROM saSaveDos[ DOS_SCREEN ]
          SETPOS   ( saSaveDos[ DOS_ROW ], saSaveDos[ DOS_COL ] )
          SETCURSOR( saSaveDos[ DOS_CURSOR ] )
          RETURN

Seealso

ANNOUNCE, REQUEST, EXIT PROCEDURE

EXTERNAL

EXTERNAL*

Declare a list of procedure or user-defined function names to the linker

Syntax

       EXTERNAL <idProcedure list>

Arguments

<idProcedure list> is the list of procedures, user-defined functions, or format procedures to add to the list of routines that will be linked into the current executable (.EXE) file.

Description

EXTERNAL is a declaration statement that specifies uncoded references to the linker. Like all other declaration statements, an EXTERNAL statement must be specified before any executable statements in either the program file, or a procedure or user-defined function definition.

During the compilation of Harbour source code, all explicit references to procedures and user-defined functions are made to the linker. In some instances, there may be no references made to procedure or user-defined function names until runtime. EXTERNAL resolves this by forcing the named procedures or user-defined functions to be linked even if they are not explicitly referenced in the source file. This is important in several instances:

. Procedures, user-defined functions, or formats referenced with macro expressions or variables

. Procedures and user-defined functions used in REPORT and LABEL FORMs and not referenced in the source code . User-defined functions used in index keys and not referenced in the source code

. ACHOICE(), DBEDIT(), or MEMOEDIT() user functions

To group common EXTERNAL declarations together, place them in a header file and then include (#include) the header file into each program (.prg) file that might indirectly use them.

EXTERNAL is a compatibility statement and therefore not recommended. It is superseded by the REQUEST statement that defines a list of module identifiers to the linker.

Examples

       .  These examples are equivalent header files consisting of
          common EXTERNAL references for REPORT FORMs:
       // Externals.ch
       EXTERNAL HARDCR
       EXTERNAL TONE
       EXTERNAL MEMOTRAN
       EXTERNAL STRTRAN
       // Externals.ch
       EXTERNAL HARDCR, TONE, MEMOTRAN, STRTRAN

Seealso

#include, REQUEST

EXIT PROCEDURE

EXIT PROCEDURE

Declare an exit procedure

Syntax

       EXIT PROCEDURE <idProcedure>
              [FIELD <idField list> [IN <idAlias>]]
              [LOCAL <identifier> [[:= <initializer>]]]
              [MEMVAR <identifer list>]
              .
              . <executable statements>
              .
              [RETURN]

Arguments

EXIT PROCEDURE declares a procedure that will be executed on program termination.

<idProcedure> is the name of the exit procedure to declare. Exit procedure names can be any length, but only the first 10 characters are significant. Names may not begin with an underscore but can contain any combination of characters, numbers, or underscores.

FIELD declares a list of identifiers to use as field names whenever encountered. If the IN clause is specified, referring to the declared name includes an implicit reference to the specified alias.

LOCAL declares and optionally initializes a list of variables or arrays whose visibility and lifetime is the current procedure.

MEMVAR declares a list of identifiers to use as private or public memory variables or arrays whenever encountered.

RETURN passes control to the next exit procedure or to the operating system, if no other exit procedures are pending.

Description

The EXIT PROCEDURE statement declares a procedure that will be executed upon program termination. EXIT procedures are called after the last executable statement in application has completed. EXIT PROCEDUREs can be used to perform common housekeeping tasks such as saving configuration settings to a file, closing a log file, or concluding a communications session.

The visibility of exit procedures is restricted to the system; therefore, it is not possible to call an EXIT PROCEDURE from a procedure or user-defined function. Exit procedures do not receive parameters.

Once the last executable statement has completed, control passes from one EXIT PROCEDURE to the next until all procedures in the exit list have been called. Control then passes to the operating system.

The ANNOUNCE statement declares a module identifier for a source (.prg) file. Once declared, EXIT PROCEDUREs are referenced with this module identifier. An application may use any number of exit procedures by explicitly REQUESTing their module identifiers.

The EXIT PROCEDUREs requested for an application are collectively referred to as the exit list. There is no mandatory execution order of procedures in the exit list; however, if an EXIT PROCEDURE is declared in the same source (.prg) file as the application’s primary routine (root), it is guaranteed to be the first exit procedure called.

Termination of a given application can be attributed to any of the following:

       . RETURNing from the primary (root) routine 

       . the QUIT command 

       . issuing a BREAK without an enclosing BEGIN SEQUENCE...END 

       . unrecoverable error

    Execution of an EXIT PROCEDURE cannot be guaranteed when the system encounters an unrecoverable error. If         an error is raised during an exit procedure, the system returns to DOS. Pending exit procedures are not called.

Examples

       .  This example illustrates construction of a simple timing 
       mechanism using INIT and EXIT PROCEDUREs: 
       // prints the amount of time required to read, 
       // sort,  and display a list of file names. 
       ANNOUNCE MySystem 
       STATIC nStart 
       PROCEDURE Main()       AEVAL( ASORT( DIRECTORY( "*.*" ) ), ; 
               { | aFileInfo | QOUT( aFileInfo[ 1 ] ) } ) 
       RETURN 
       INIT PROCEDURE MyInit() 
          nStart := SECONDS() 
       RETURN 
       EXIT PROCEDURE MyExit() 
          ? 
          ? "Elapsed Time: " 
          ?? SECONDS() - nStart 
       RETURN

See Also

ANNOUNCE, REQUEST, INIT PROCEDURE

ANNOUNCE

ANNOUNCE

Declare a module identifier

Syntax

     ANNOUNCE <idModule>

Arguments

<idModule> is a module identifier name.

Description

ANNOUNCE is a declaration statement that defines a module identifier. A linker may use this identifier later to satisfy pending module REQUESTs. ANNOUNCE and REQUEST provide a mechanism for managing application modules (.prg files).

Specify ANNOUNCE statements prior to any executable statements in a program file. A source (.prg) file can only have one module identifier; all subsequent ANNOUNCE declarations produce a compiler warning and will be ignored.

Module identifiers must be unique and should not duplicate the name of any procedures or user-defined functions in a source (.prg) file.

Examples.

// This example illustrates the ANNOUNCE declaration:

        ANNOUNCE CustomInit
        INIT PROCEDURE MyInit

           ? "Hypothetical Industries, Inc."

           RETURN

        /* 
        The above program module, CustomInit, should be compiled with the /N
        option.  Subsequently, the program is addressed in the source code of
        another program module through use of the REQUEST statement */

        REQUEST CustomInit

        which causes the module CustomInit to be linked into the resultant
        executable (.EXE) file.


Seealso 


REQUEST

hb_Translate()

HB_TRANSLATE()

Translate a string from one code page to the other

Syntax

      HB_TRANSLATE( <cSrcText>, [<cPageFrom>], [<cPageTo>] ) --> cDstText

Arguments

<cSrcText> Is the source string to translate.

<cPageFrom> Is the optional character code page ID of the source string. If not specified, the default code page is used.

<cPageTo> Is the optional character code page ID of the destination string. If not specified, the default code page is used.

Returns

HB_TRANSLATE() return destination string converted from the source string.

Description

HB_TRANSLATE() try to convert a source string from one code page into the other. If a code page ID is not recognized, or not linked in, the default code page is used. HB_TRANSLATE() is used usually to convert between the Dos and the Windows code pages of the same language.

NOTE: If the source code page and target code page does not have the same number of characters, a translation can not be done and the destination string is a copy of the source string.

NOTE: You must REQUEST every code page module you intend to use. For example: to use the Russian RU866 code page you must add the following to your program: REQUEST HB_CODEPAGE_RU866

Examples

      REQUEST HB_CODEPAGE_DE
      REQUEST HB_CODEPAGE_DEWIN
      PROCEDURE Main()
         LOCAL cTxt := "A" + Chr( 142 ) + "BC"
         ? "German CP-850 text:", cTxt
         ? "German Windows-1252 text:", hb_Translate( cTxt, "DE", "DEWIN" )
         RETURN

Compliance

This function is a Harbour Extension.

Platforms

All

Files

Libraty are rtl, codepage

Seealso

HB_LANGSELECT(), HB_CDPSELECT(), NATIONMSG(), REQUEST

hb_langSelect()

HB_LANGSELECT()

Select a specific nation message module

Syntax

      HB_LANGSELECT( [ <cNewLang> ][, <cCodepage> ] ) --> cOldLang

Arguments

<cNewLang> The optional ID of the country language module. Possible values for <cNewLang> are below as defined in the Lang library, sorted by language. <cCodepage> Optional codepage ID into which the language module strings are automatically converted by Harbour.

      Language              <cNewLang>
      --------------------- ----------------------------------
      Basque                eu
      Belorussian           be
      Bulgarian             bg
      Catalan               ca
      Chinese Simplified    zh_sim
      Chinese Traditional   zh_tra
      Croatian              hr
      Czech                 cs
      Dutch                 nl
      Esperanto             eo
      French                fr
      Galician              gl
      German                de
      Greek                 el
      Hebrew                he
      Hungarian             hu
      Icelandic             is
      Indonesian            id
      Italian               it
      Korean                ko
      Lithuanian            lt
      Polish                pl
      Portuguese            pt
      Romanian              ro
      Russian               ru
      Serbian (cyrillic)    sr_cyr
      Serbian (latin)       sr_lat
      Slovak                sk
      Slovenian             sl
      Spanish               es
      Swedish               sv
      Turkish               tr
      Ukrainian             uk

Returns

<cOldLang> The old language indentifier

Description

This function set a default language module for date/month names, internal warnigs, NatMsg messages and internal errors. When a Lang ID is selected all messages will be output with the current language selected until another one is selected or the program ends. The default language is English (cLang == “EN”).

NOTE: You must REQUEST every language module you intend to use. For example: to use the Russian RU866 language you must add the following to your program: REQUEST HB_LANG_RU866

Examples

      REQUEST HB_LANG_PT
      REQUEST HB_LANG_RO
      REQUEST HB_LANG_ES
      PROCEDURE Main()
         HB_LANGSELECT( "pt" )       // Default language is now Portuguese
         ? CDOW( Date() )            // Segunda-feira
         ? "Old language id selected is ", HB_LANGSELECT()   // PT
         HB_LANGSELECT( "ro" )       // Default language is now Romanian
         ? CMONTH( Date() )          // Mai
         ? "Old language id selected is ", HB_LANGSELECT()   // RO
         HB_LANGSELECT( "es" )       // Default language is now Spanish
         ? CMONTH( Date() )          // Mayo
         ? CDOW( Date() )            // Lunes
         RETURN

Tests

      See tests/langapi.prg, tests/langmsg.prg

Compliance

Harbour

Platforms

All

Files

Libraty are rtl, lang

Seealso

HB_LANGNAME(), HB_CDPSELECT(), NATIONMSG(), REQUEST

hb_langMessage()

HB_LANGMESSAGE()

Returns international strings messages and errors

Syntax

      HB_LANGMESSAGE( <nMsg> ) --> cMessage

Arguments

<nMsg> is the message number to get.

Returns

HB_LANGMESSAGE() return the text associated with the code <nMsg>.

Description

HB_LANGMESSAGE() is similar to NATIONMSG() but give access to the whole list of language messages: Day and month names, generic error messages, internal errors, and others…

Use the header file hblang.ch for a list of base values for <nMsg>.

Examples

      #include "hblang.ch"
      REQUEST HB_LANG_ES
      PROCEDURE Main()
         // English: Monday
         ? "English:", HB_LANGMESSAGE( HB_LANG_ITEM_BASE_DAY + 1 )
          "ES" )
         // Spanish: Lunes
         ? "Spanish:", HB_LANGMESSAGE( HB_LANG_ITEM_BASE_DAY + 1 )
         RETURN

Compliance

Harbour

Platforms

All

Files

Library are rtl, lang Header is hblang.ch

Seealso

HB_LANGSELECT(), NATIONMSG(), REQUEST