SET TABLE TITLES

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 11 (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 4D dialog boxes such as the Query editor, within the Application environment (more specifically, when the editors are called via the 4D language commands).

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 4D 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 4D. 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 4D dialog boxes and forms using dynamic names when they are called via language commands (the real structure of the database is displayed when the editor or form is called from a menu command in Design mode). 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.

Notes:

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

Plug-ins always access the "virtual" structure as specified by this command.

Example

You are building a 4D application that you plan to sell internationally. Therefore, you must carefully consider localization issues. Regarding the standard 4D dialog boxes that can appear in the Application environment 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 (Text)
     ` TRANSLATE TABLES AND FIELDS (LanguageCode)

   C_TEXT($1) `language code
   C_LONGINT($vlTable;$vlField)
   C_TEXT($Language)
   $Language:=$1

   For($vlTable;1;Get last table number)  ` Pass through each table
      If($vlTable#(Table(->[Translations])))  `Do not translate table of translations
            ` Check if there is a translation of the table name for the specified language
         QUERY([Translations];[Translations]LanguageCode=$Language;*)  `desired language
         QUERY([Translations]; & ;[Translations]TableID=$vlTable;*)  `table number
         QUERY([Translations]; & ;[Translations]FieldID=0)  `field number = 0 means that it is a table name
         If(Is table number valid($vlTable))  `check that the table still exists
            If(Records in selection([Translations])=0)
                  ` Otherwise, create the record
               CREATE RECORD([Translations])
               [Traductions]LanguageCode:=$Language
               [Traductions]TableID:=$vlTable
               [Traductions]FieldID:=0
                  ` The name of the translated table will need to be entered
               [Translations]Translation:=Table name($vlTable)+" in "+$Language
               SAVE RECORD([Translations])
            End if 

            For($vlField;1;Get last field number($vlTable))
                  ` Check if there is a translation of the field name for the specified language
               QUERY([Translations];[Translations]LanguageCode=$Language;*)  `desired language
               QUERY([Translations]; & ;[Translations]TableID=$vlTable;*)  `table number
               QUERY([Translations]; & ;[Translations]FieldID=$vlField)  `field number
               If(Is field number valid($vlTable;$vlField))
                  If(Records in selection([Translations])=0)
                        ` Otherwise, create the record
                     CREATE RECORD([Translations])
                     [Traductions]LanguageCode:=$Language
                     [Traductions]TableID:=$vlTable
                     [Traductions]FieldID:=$vlField
                        ` The name of the translated field will need to be entered
                     [Traductions]Translation:=Field name($vlTable;$vlField)+" in "+$Language
                     SAVE RECORD([Translations])
                  End if 
               Else
                  If(Records in selection([Translations])#0)
                        ` If the field no longer exists, remove the translation
                     DELETE RECORD([Translations])
                  End if 
               End if 
            End for 
         Else
            If(Records in selection([Translations])#0)
                  ` If the table no longer exists, remove the translation
               DELETE RECORD([Translations])
            End if 
         End if  
      End if  
   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 (Text)
      ` LOCALIZED TABLES AND FIELDS (LanguageCode)

   C_TEXT($1)  `Language code 
   C_LONGINT($vlTable;$vlField)
   C_TEXT($Language)
   C_LONGINT($vlTableNum;$vlFieldNum)
   $Language:=$1

      `Updating table names
   ARRAY TEXT($asNames;0)  ` Initialize arrays for SET TABLE TITLES and SET FIELD TITLES
   ARRAY INTEGER($aiNumbers;0)
   QUERY([Translations];[Translations]LanguageCode=$Language;*)
   QUERY([Translations]; & ;[Translations]FieldID=0)  `thus table names
   SELECTION TO ARRAY([Translations]Translation;$asNames;[Translations]TableID;$aiNumbers)
   SET TABLE TITLES($asNames;$aiNumbers)

      `Updating field names
   $vlTableNum:=Get last table number  ` Get number of tables in database
   For($vlTable;1;$vlTableNum)  ` Pass through each table
      If(Is table number valid($vlTable))
         QUERY([Translations];[Translations]LanguageCode=$Language;*)
         QUERY([Translations]; & ;[Translations]TableID=$vlTable;*)
         QUERY([Translations]; & ;[Translations]FieldID#0)  `avoid the zero that serves as table name
         SELECTION TO ARRAY([Translations]Translation;$asNames;[Translations]FieldID;$aiNumbers)
         SET FIELD TITLES(Table($vlTable)->;$asNames;$aiNumbers)
      End if
   End for 

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

See Also

Get last table number, SET FIELD TITLES, Table name.


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next