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:
Fnd_Host_*, eleven methods the host must have, because a component cannot do these things itself: run a formula in the host (Fnd_Host_ExecuteFormula), read and write the host's lists (Fnd_Host_ListToArray,Fnd_Host_ArrayToList,Fnd_Host_SaveList), read a form's size, fetch a picture from the host's library, and a few toolbar callbacks. Foundation creates any that are missing the first time it starts in an interpreted host, and reports what it made.Fnd_Hook_*, twenty-seven methods the host may have. Foundation calls each at a defined moment and does something sensible when it is absent. Your customisation lives in them: the database name, the navigation palette, which fields the Find dialog offers, what happens before a record is deleted.
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".
| Module | Does |
|---|---|
Fnd_Gen | initialisation, database info, strings, utilities |
Fnd_Shell | startup, quit, the menu bar, the standard dialogs (Find, Sort, Open Table, Administration, Special Functions) |
Fnd_Menu, Fnd_Tlbr, Fnd_Bttn | menus, toolbars, button pictures |
Fnd_Nav | the navigation palette |
Fnd_IO, Fnd_Rec | record windows, record navigation, new and delete |
Fnd_Out | list windows: columns, layouts, View Options, row styles |
Fnd_Find, Fnd_Sort, Fnd_List | Find and Sort dialogs, editable lists |
Fnd_Wnd | window opening, positions, the Window menu |
Fnd_Pref, Fnd_Loc, Fnd_VS | preferences, localisation, virtual structure (renaming tables and fields for the user) |
Fnd_Dlg, Fnd_Msg, Fnd_Art | alerts and confirms, progress messages, About box and startup dialog |
Fnd_Log, Fnd_Pswd, Fnd_SqNo, Fnd_Date, Fnd_Text | logging, passwords, sequence numbers, dates, text |
Fnd_Reg, Fnd_RegG | licensing your application (optional), and generating its unlock codes |
Fnd_FCS | build-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.