Foundation 6

2. How Foundation works

Component and host

Foundation is a 4D component: a project with methods, forms, resources and no tables, loaded by the database that contains your tables, which Foundation calls the host. The component cannot see your tables, forms or lists directly. Everything it does with them goes through pointers you pass and through methods you supply in the host:

Chapter 4 lists every one of them.

Modules

Methods are grouped by prefix: Fnd_Dlg_Alert, Fnd_Pref_GetText, Fnd_Wnd_OpenWindow. The module is the unit of documentation and of history. Fnd_Gen is required by everything; Fnd_Shell is the application shell that Fnd_Shell_OnStartup brings up; the rest are used as needed. Each module has an _Init method that runs once per process and an _Info method that answers "version" and "name".

ModuleDoes
Fnd_Geninitialisation, database info, strings, utilities
Fnd_Shellstartup, quit, the menu bar, the standard dialogs (Find, Sort, Open Table, Administration, Special Functions)
Fnd_Menu, Fnd_Tlbr, Fnd_Bttnmenus, toolbars, button pictures
Fnd_Navthe navigation palette
Fnd_IO, Fnd_Recrecord windows, record navigation, new and delete
Fnd_Outlist windows: columns, layouts, View Options, row styles
Fnd_Find, Fnd_Sort, Fnd_ListFind and Sort dialogs, editable lists
Fnd_Wndwindow opening, positions, the Window menu
Fnd_Pref, Fnd_Loc, Fnd_VSpreferences, localisation, virtual structure (renaming tables and fields for the user)
Fnd_Dlg, Fnd_Msg, Fnd_Artalerts and confirms, progress messages, About box and startup dialog
Fnd_Log, Fnd_Pswd, Fnd_SqNo, Fnd_Date, Fnd_Textlogging, passwords, sequence numbers, dates, text
Fnd_Reg, Fnd_RegGlicensing your application (optional), and generating its unlock codes
Fnd_FCSbuild-time tooling for Foundation's own developers; not used at runtime (chapter 11)

Names

Every Foundation object begins with Fnd_. Never name anything of your own Fnd_* except the hooks and host methods, whose names Foundation expects. Foundation's own variables end in a type suffix (_t, _i, _b, _ptr, _pic), a convention you will meet in every header and may adopt or not.

Exposed names are in US spelling (Fnd_Gen_Initialized); the code is American by birth and names are matched by machines.

Windows and processes

Each table opens in its own list window and each record in its own window, each in its own process. The Window menu lists them. Opening is always through Fnd_Wnd_* and Fnd_IO_*, never Open window by hand, so that positions are remembered, the menu bar is installed and the quit sequence can close them. Fnd_Shell_OnExit asks every Foundation window to close and waits up to thirty seconds for them.

State

Foundation 6 is removing its interprocess variables. Module state lives in objects: per process in Fnd.<Module>, shared across processes in Storage.Fnd.<Module>. From the host you see neither; you see methods. Where you need something to persist, use preferences (chapter 7).

Localisation

No user-visible string is hard-coded. Fnd_Loc_GetString("Fnd_Gen"; "Stop") looks up the label Stop in the list Fnd_Gen, then the translation at the same position in Fnd_Gen_EN, Fnd_Gen_FR or whichever language is current. Your own strings work the same way: a key list and one list per language in the host, read through Fnd_Host_ListToArray. Foundation Product Sales ships Loc_General, Loc_General_EN and Loc_General_FR. Foundation itself carries English and French (eighteen list pairs). Chapter 8 covers adding a language.

Compiled and interpreted

Foundation assumes an interpreted host is being developed and a compiled one is being used. Interpreted, it creates missing host methods and offers to create its optional tables, keeps developer menus visible, and treats Quit as "return to Design". Compiled, it reports instead of asking, and Quit quits. Test compiled before you ship.

The demo

Foundation Product Sales is a complete host: four tables, every hook and host method, input forms, list windows, toolbars, two languages and an About box. When this guide says "see FPS", that is where to look.