SET TABLE TITLES

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 2004.2 (Modified)


SET TABLE TITLES (tableTitles; tableNumbers{; *})

ParameterTypeDescription
tableTitlesString ArrayTable names as they must appear in dialog boxes
tableNumbersNumeric ArrayActual table numbers
*Use the custom names in the formula editor

Description

SET TABLE TITLES enables you to mask, rename, and reorder the tables of your database when they appear in standard 4th Dimension dialog boxes such as the Query editor, within the User or Custom Menus environments.

Using this command, you can also rename on the fly the table labels in your forms, if you used dynamic names. For more information about inserting dynamic field and table names in the forms, refer to the 4th Dimension Design Reference manual.

The tableTitles and tableNumbers arrays must be synchronized. In the tableTitles array, you pass the names of the tables as you would like them to appear. If you do not want to show a particular table, do not include its name or new title in the array. The tables will appear in the order you specify in this array. In each element of the tableNumbers array, you pass the actual table number corresponding to the table name or new title passed in the same element number in the tableTitles array.

For example, you have a database composed of the tables A, B, and C, created in that order. You want these tables to appear as X, Y, and Z. In addition you do not want to show table B. Finally, you want to show Z and X, in that order. To do so, you pass Z and X in a two-element tableTitles array, and you pass 3 and 1 in a two-element tableNumbers array.

The optional * parameter lets you indicate whether or not custom names defined using this command can be used in 4D formulas.

By default, when this parameter is omitted, formulas executed in 4D cannot use these custom names; it is necessary to use the real table names.

If the * parameter is passed, the names defined by this command can be used in the formulas executed by 4th Dimension. Be careful in this case, the custom names must not contain characters that are "forbidden" by the 4D language interpreter, like -?*! (for more information, refer to the "Identifiers" section).

Note: At the formula editor level, the execution of this command without the * parameter does not modify any settings made previously with the * parameter. In other words, the formula editor always displays the custom name set via the last call of the command with the * parameter.

SET TABLE TITLES does NOT change the actual structure of your database. It only affects subsequent uses of the standard 4th Dimension dialog boxes and forms using dynamic names within the User or Custom Menus environments. The scope of the SET TABLE TITLES command is the worksession. One benefit in Client/Server is that several 4D Client stations can simultaneously "see" your database in different ways. You can call SET TABLE TITLES as many times as you want.

Use the SET TABLE TITLES command for:

Dynamically localizing a database.

Showing tables the way you want, independent from the actual definition of your database.

Showing tables in a way that depends on the identity or custom privileges of a user.

WARNING: SET TABLE TITLES does NOT override the Invisible property of a table. When a table is set to be invisible at the Design level of your database, even though it is included in a call to SET TABLE TITLES, it will not appear.

Example

You are building a 4D application that you plan to sell internationally. Therefore, you must carefully consider localization issues. Regarding the standard 4th Dimension dialog boxes that can appear in the User and Custom Menus environments and your forms that use dynamic names, you can address localization needs by using a [Translations] table and a few project methods to create and use fields localized for any number of countries.

In your database, add the following table:

Then, create the TRANSLATE TABLES AND FIELDS project method listed below. This method browses the actual structure of your database and creates all the necessary [Translations] records for the localization corresponding to the language passed as parameter.

     ` TRANSLATE TABLES AND FIELDS project method
     ` TRANSLATE TABLES AND FIELDS ( String )
     ` TRANSLATE TABLES AND FIELDS ( Language )

   C_STRING(31;$1)
   C_LONGINT($vlTable;$vlField)

   For ($vlTable;1;Count tables) ` Loop through the tables
         ` Check if there is a translation of the table name for the specified language
      QUERY([Translations];[Translations]Actual Name=Table name($vlTable);*) 
      QUERY([Translations]; & ;[Translations]Language=$1)
      If (Records in selection([Translations])=0)
            ` If not, create the record
         CREATE RECORD([Translations])
         [Translations]Actual Name:=Table name($vlTable)
         [Translations]Language:=$1
            ` The translated table name will have to be entered
         SAVE RECORD([Translations])
      End if 
      For ($vlField;1;Count fields($vlTable))
            ` Check if there is a translation of the field name for the specified language
         QUERY([Translations];[Translations]Actual Name=Field name($vlTable;$vlField);*)
         QUERY([Translations]; & ;[Translations]Language=$1)
         If (Records in selection([Translations])=0)
               ` If not, create the record
            CREATE RECORD([Translations])
            [Translations]Actual Name:=Field name($vlTable;$vlField)
            [Translations]Language:=$1
               ` The translated field name will have to be entered
            SAVE RECORD([Translations])
         End if 
      End for 
   End for 

At this point, if you execute the following line, you create as many records as needed for a Spanish localization of the tables and fields titles.

   TRANSLATE TABLES AND FIELDS ("Spanish")

After this call has been executed, you can then enter the [Translations]Translated Name for each of the newly created records.

Finally, each time you want to show your database's standard 4D dialog boxes or forms with dynamic titles using the Spanish localization, you execute the following line:

   LOCALIZED TABLES AND FIELDS ("Spanish")

with the project method LOCALIZED TABLES AND FIELDS:

      ` LOCALIZED TABLES AND FIELDS global method
      ` LOCALIZED TABLES AND FIELDS ( String )
      ` LOCALIZED TABLES AND FIELDS ( Language )

   C_STRING(63;$1)
   C_LONGINT($vlTable;$vlNbTable;$vlField;$vlNbField)

   $vlNbTable:=Count tables  ` Get the number of tables present in the database
   ARRAY STRING(31;$asTableName;$vlNbTable)  ` Initialize the arrays to be passed to SET TABLE TITLES
   ARRAY INTEGER($aiTableNumber;$vlNbTable)
   For ($vlTable;1;$vlNbTable)  ` Loop through the tables
      $asTableName{$vlTable}:=Table name($vlTable)  ` Get the name of the table
      $aiTableNumber{$vlTable}:=$vlTable  ` Store the actual table number
      QUERY([Translations];[Translations]Actual Name=$asTableName{$vlTable};*)  ` Look for the translation
      QUERY([Translations]; & ;[Translations]Language=$1)
      If (Records in selection([Translations])>0)
         $asTableName{$vlTable}:=[Translations]Translated Name  ` If available, use the localized table name
      End if 
      $vlNbField:=Count fields($vlTable)  ` Get the number of fields for that table
      ARRAY STRING(31;$asFieldName;$vlNbField)  ` Initialize the arrays to be passed to SET FIELD TITLES
      ARRAY INTEGER($aiFieldNumber;$vlNbField)
      For ($vlField;1;$vlNbField)  ` Loop through the fields
         $asFieldName{$vlField}:=Field name($vlTable;$vlField)  ` Get the name of the field
         $aiFieldNumber{$vlField}:=$vlField  ` Store the actual field number
         QUERY([Translations];[Translations]Actual Name=$asFieldName{$vlField};*)  
            ` Look for the translation
         QUERY([Translations]; & ;[Translations]Language=$1)
         If (Records in selection([Translations])>0)
            $asFieldName{$vlField}:=[Translations]Translated Name  ` If available, use the localized field name
         End if 
      End for 
      SORT ARRAY($asFieldName;$aiFieldNumber;>)
      SET FIELD TITLES(Table($vlTable)->;$asFieldName;$aiFieldNumber)
   End for 
   SORT ARRAY($asTableName;$aiTableNumber;>)
   SET TABLE TITLES($asTableName;$aiTableNumber)

Note that new localizations can be added to the database without modifying or recompiling the code.

See Also

Count tables, SET FIELD TITLES, Table name.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next