Virtual User Mode
This is a component designed to replicate the User Mode features in a custom menu application. It can be useful, for example, in engined applications or build remote clients.
Other methods that have the "shared" attribute (Menu_action@) are internally called from the menu.
This is a self contained standard v12 component. No external plugins are components are required. Simply install it in the Components folder.
Note: The component is not tested for non unicode mode but should be compatible. See method Document_Guess_encoding.
Launch the host application and create a new menu item in your main menu bar. Give it a title (ex. USER MODE) and assign its action as "User_Install_user_mode". This is the component's only entry point. Alternatively, you could call the method from a button object, etc.
The virtual user mode offers basic menus to import/export, switch tables/forms, search, sort, apply formula, etc. and access to built in tools (Quick Report, Label Editor).
There are also several additions to make life easier; toggle read write/read only and set automatic relations. The latter is specifically intended for use in conjunction with the Quick Report Editor.
The component obtains the list of table forms from the verify log of your host application. If you don't see the list of tables. verify the application and call User_Install_user_mode again. The form names are extracted using XSLT.
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="no" indent="yes" /> <xsl:key name="title" match="/verifylog/step" use="@title" /> <xsl:template match="/"> <xsl:choose> <xsl:when test="key('title', 'テーブルフォームをチェック')"> <xsl:copy-of select="key('title', 'テーブルフォームをチェック')" /> </xsl:when> <xsl:when test="key('title', 'Check Table Forms')"> <xsl:copy-of select="key('title', 'Check Table Forms')" /> </xsl:when> <xsl:when test="key('title', 'Vérification des formulaires table')"> <xsl:copy-of select="key('title', 'Vérification des formulaires table')" /> </xsl:when> <xsl:when test="key('title', 'Prüfe Tabellen-Formulare')"> <xsl:copy-of select="key('title', 'Prüfe Tabellen-Formulare')" /> </xsl:when> <xsl:when test="key('title', 'Verificación de los formularios tabla')"> <xsl:copy-of select="key('title', 'Verificación de los formularios tabla')" /> </xsl:when> <xsl:when test="key('title', 'Verificação dos formulários tabela')"> <xsl:copy-of select="key('title', 'Verificação dos formulários tabela')" /> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet>
Note: This could be improved in v13 with the new Source Tool Kit commands.
The component works by calling MODIFY SELECTION in the main process. The behaviour is therefore not exactly the same as the real User Mode, in the following aspects.
For the "Return to design" action to work, one must click the close box, to cancel the MODIFY SELECTION event loop.
Double clicking in a blank row will not create a new record.
The window title does not display the number of records in the current selection.
The table list is not available as a separate window; instead it is integrated in the "Record" menu.
- Customisation Hints
This routine is used to guess the encoding of a file about to be imported. The logic is as follows;
- look for BOM (UTF-16, UTF-8)
- if no BOM is found, test for SHIFT_JIS byte sequence
- if test fails, test for UTF-8 byte sequence
- if test fails, assume ISO-8859-15
- if document can't be read, assume UTF-8
(non unicode mode)
- if no BOM is found, test for SHIFT_JIS byte sequence (locale=ja) or assume MacRoman.
You might want to modify the priorities or set a different default according to local expectations.
The component is pure 4D code so you are free to add/modify the menu. For example, you might want to add SQL EXPORT DATABASE to the File/Export menu, or a SQL query editor to the Records/Query menu.
This is where the pseudo user mode environment is created. You could, for example, set the size and location of the main window, add/remove menu items here. Or, you might want to use v13 STK commands or API Pack plugins to speed up the construction of forms list.
The import-export projects used internally was change from BLOB to TEXT. No need to make changes in the host.
The missing Cut menu (command+X) was added.