Foundation 6

4. Hooks and host methods

A hook is a method in your database that Foundation calls at a defined moment, by name, with EXECUTE METHOD. If the method is absent Foundation does something sensible. If present, it must be shared (the "Shared by components and host database" attribute), or the call fails. Foundation creates each hook it needs on first startup in an interpreted host, with the expected parameters and a comment saying what it is for, so the easiest way to get one is to let Foundation make it and then fill it in. Foundation Product Sales has a working copy of every one.

A host method (Fnd_Host_*) is the same mechanism used the other way: a small method Foundation needs you to have because a component cannot do the thing itself. Foundation creates these too and you normally never edit them.

Shell

HookCalledUse it to
Fnd_Hook_Shell_Setuponce at startup, before anything is shownset the database name, version, copyright and URL with Fnd_Gen_SetDatabaseInfo; the About box history with Fnd_Art_VersionHistory
Fnd_Hook_Shell_Startupafter setup, while the startup dialog showsyour own startup code: number formats, defaults, opening a first window
Fnd_Hook_Shell_InitPluginsat startup, single-user and serveractivate plugins
Fnd_Hook_Shell_VirtualStructureat startupgive tables and fields the names the user should see (Fnd_VS_*)
Fnd_Hook_Shell_NavPaletteeach time the palette is builtFnd_Nav_AddButtonTable(->[Table]; …) per table, Fnd_Nav_AddButtonMethod("method"; "label"; …) per command, then Fnd_Nav_Display
Fnd_Hook_Shell_OpenTablebefore the Open Table dialogrestrict or reorder the tables offered
Fnd_Hook_Shell_Findbefore the Find dialogFnd_Find_AddItem the fields to offer for the current table
Fnd_Hook_Shell_Sortbefore the Sort dialogthe fields to offer, likewise
Fnd_Hook_Shell_QueryEditorfrom the Query Editor commanddisplay a query editor for the current table; Foundation first syncs the list window's selection
Fnd_Hook_Shell_ModifyRecordsfrom the Modify Records commandshow your own batch-change dialog
Fnd_Hook_Shell_Printfrom Printyour own print dialog or report
Fnd_Hook_Shell_Administrationfrom Administrationyour own admin dialog
Fnd_Hook_Shell_SpecialFunctionsfrom Special FunctionsFnd_List_AddItem your own commands to its list
Fnd_Hook_Shell_Quitjust before QUIT 4Dlast-moment cleanup; return True to allow the quit, False to abort it

Records and record windows

HookCalledUse it to
Fnd_Hook_IO_DisplayTablejust before a list window openswindow title, type and size for a table (Fnd_Wnd_*), your process object's init
Fnd_Hook_IO_DisplayRecordjust before a record window opensthe same for a record: FPS sets "Invoice: 1234" here, and a fixed window for [CompanyInfo]
Fnd_Hook_IO_InputFormMethodon every event of every input formbehaviour common to all your record windows
Fnd_Hook_IO_OutputFormMethodon every event of a classic output formlikewise for classic list forms
Fnd_Hook_IO_InputFormButtonwhen an inherited button (Save, Cancel, First, Next…) is clicked, with the button name in lower casevalidate before Save; return False to stop the default action
Fnd_Hook_IO_SelectionChangedwhenever Foundation changes the current table's selection (find, sort, show all)react to the new selection; Fnd_Gen_CurrentTable says which table
Fnd_Hook_Rec_Newwhen the user asks for a new record, with a pointer to the tablereturn True to let Foundation create it, False to handle it yourself
Fnd_Hook_Rec_Deletebefore Foundation deletes; the UserSet set holds the recordsreturn True for Foundation's warning and delete, False to handle it yourself

Lists, menus, output

HookCalledUse it to
Fnd_Hook_List_SetEditableListsat startupname the 4D lists the user may edit in the list editor
Fnd_Hook_Menu_UpdateMenuBareach time Foundation rebuilds the menu barenable, disable or add menu items
Fnd_Hook_Out_RowStylefor every row a list window drawsreturn font, colour and style for the row from its record (chapter 5)
Fnd_Hook_Out_ContextMenuon a right-click in a list windowadd your own items to the menu (chapter 5)
Fnd_Hook_SqNo_SetIDFieldwhen sequence numbers need a table's key fieldreturn a pointer to it when it is not the first field

Host methods

MethodFoundation uses it to
Fnd_Host_ExecuteFormularun a formula text in the host's context (the OK variable, your methods)
Fnd_Host_GetIntegerValueread a host variable by name
Fnd_Host_GetFormPropertiesread the size of one of your forms
Fnd_Host_ListToArray, Fnd_Host_ArrayToList, Fnd_Host_SaveListread, write and persist the host's 4D lists: localisation, editable lists, preferences
Fnd_Host_GetPictureFromLibraryfetch a picture from the host's library by name
Fnd_Host_IO_DisplayDialogshow one of the host's dialogs
Fnd_Host_Tlbr_ButtonClck, Fnd_Host_Tlbr_SetBtnPict, Fnd_Host_Tlbr_SetMessagetoolbar callbacks for the classic output form

Each of these is a few lines. If you delete one, delete its Compiler_Fnd_Host_* method too; Foundation recreates both.

When a hook's signature changes

Foundation compares an existing hook's declared parameters with the ones it now passes (interpreted hosts only) and reports a mismatch at startup rather than rewriting your code. Release/UPGRADING.md lists every such change by release.