TDict - Data Dictionary
Source: source/classes/tdict.prg
Standalone class
TDict implements a data dictionary system that manages a collection of database tables (DBFs), menus, and reports. It stores metadata across 15+ system tables (oTables) covering table definitions, field definitions, indexes, relations, menus, reports, users, and security. The dictionary can auto-build missing system tables (lAutoBuild) and provides methods for creating tables, opening databases, loading menus, running reports, and importing files.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cPath | Character | Base path where dictionary files are stored |
lAutoBuild | Logical | .T. to automatically create missing system tables |
oTables | Array | Array of 15+ TDatabase objects for system tables |
Methods
| Method | Description |
|---|---|
New( cPath ) | Create a new data dictionary at the given path |
Activate() | Open all system tables and activate the dictionary |
CreateTable( cTbl ) | Create a new user table defined in the dictionary |
OpenDataBase( cDbName ) | Open a named database and all its tables |
OpenTable( cTbl ) | Open a specific table by name |
LoadMenu( cMenu ) | Load a menu definition from the dictionary; returns TMenu |
Report( cReport ) | Run a report defined in the dictionary |
Import( cMask ) | Import files matching a file mask into the dictionary |
LoadWebBrowse( cTbl ) | Load web browse configuration for a table |
LoadWebRecord( cTbl ) | Load web record form configuration for a table |
WebRecSave( cTbl ) | Save web record configuration for a table |
Example: Create and Use Dictionary
#include "FiveWin.ch"
function Main()
local oDict
// Create a data dictionary in the data directory
oDict := TDict():New( ".\data\" )
oDict:lAutoBuild := .T.
oDict:Activate()
// Create a new user table
oDict:CreateTable( "INVOICES" )
// Open a database
oDict:OpenDataBase( "SALES" )
// Load a menu
DEFINE WINDOW oWnd TITLE "Dictionary Demo" SIZE 800, 600
oDict:LoadMenu( "MAIN" ):Activate( oWnd )
// Run a report
oDict:Report( "CUSTOMER_LIST" )
ACTIVATE WINDOW oWnd
return nil
Notes
- The dictionary maintains system tables for table definitions (
_TABLES.DBF), field definitions (_FIELDS.DBF), indexes (_INDEXES.DBF), relations, menus, reports, users, groups, and permissions. - When
lAutoBuildis.T., any missing system tables are automatically created whenActivate()is called. - Use
CreateTable()to materialize a user-defined table based on the dictionary metadata. The table structure is read from the_FIELDSsystem table. LoadMenu()reads menu definitions from the dictionary and returns a fully constructedTMenuobject ready for activation.