KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Virtual structures
PRODUCT: 4D | VERSION: 6.7 | PLATFORM: Mac & Win
Published On: December 9, 2003

4D has two commands that allow you to define a virtual structure (i.e. renaming or hiding tables or fields). Please note that you cannot use the command SET FIELD TITLES without using the command SET TABLE TITLE.This means that you will need to define the whole sructure even if you just want to rename a field or delete a field.

Here is an example of code that you can use:

$NbTables:=Count tables
ARRAY TEXT(at_tablenames;$NbTables)
ARRAY LONGINT(al_TableIDs;$NbTables)
ARRAY TEXT(at_fieldnames;$NbTables;0)
ARRAY LONGINT(al_fieldIDs;$NbTables;0)
` We are going to retrieve the current structure description
For ($i_table;1;$NbTables)
  at_tablenames{$i_table}:=Table name($i_table)
  al_TableIDs{$i_table}:=$i_table
  $NbFields:=Count fields($i_table)
  INSERT ELEMENT(at_fieldnames{$i_table};1;$NbFields)
  INSERT ELEMENT(al_fieldIDs{$i_table};1;$NbFields)

  For ($i_field;1;$NbFields)
    at_fieldnames{$i_table}{$i_field}:=Field name($i_table;$i_field)
    al_fieldIDs{$i_table}{$i_field}:=$i_field
  End for
End for
` We are going to change the names
For ($i_table;1;$NbTables)
  $NbFields:=Count fields($i_table)
  at_tablenames{$i_table}:="*-"+at_tablenames{$i_table}+"-*"
  For ($i_field;1;$NbFields)
    a t_fieldnames{$i_table}{$i_field}:="*-"+at_fieldnames{$i_table}{$i_field}+"-*"
  End for
End for
` The new structure will be applied
SET TABLE TITLES(at_tablenames;al_TableIDs)
For ($i_table;1;$NbTables)
  SET FIELD TITLES(Table($i_table)->;at_fieldnames{$i_table};al_fieldIDs{$i_table})
End for

With the code described above, we are going to retrieve the current structure. It will be defined in four arrays. You may modify these arrays, remove or renames elements and then apply the new structure file.