The TSMDBGrid component, part of the popular, freeware Scalabium SMComponent Library created by Mike Shkolnik, is a powerful, extended successor to Delphi’s native TDBGrid. It is designed to inject advanced grid features into VCL database applications natively, without requiring heavy, expensive third-party suites or complex architectural overwrites. 🌟 Core Features of TSMDBGrid
Unlike the vanilla TDBGrid, which requires extensive manual coding in events like OnDrawColumnCell just to change basic behaviors, TSMDBGrid handles advanced UI patterns right out of the box:
Enhanced Typography & Titles: Out of the box support for multiline word-wrap column titles.
In-Grid Boolean Controls: Automatically renders Boolean database fields as clean, interactive checkboxes rather than displaying text strings like “True/False”.
Mass Record Selection: Allows users to select multiple records easily using standard checkboxes in the indicator column alongside standard keyboard selection rules.
Custom Indicator & Layouts: Customizable glyphs and flexible width definitions for the left-hand row indicator column.
Built-in Context Menu: Features an integrated, standard PopupMenu configured with instant operations like Add/Edit/Delete records, data printing/exporting, layout save/restore, and batch selections.
Column Locking: Built-in support to fix/freeze specific columns horizontally while scrolling through wide data pools.
Security Restrictions: Properties to natively block or allow record insertion/deletion safely at the UI grid level. ⚙️ Master Key Coding Techniques 1. Native Grid Sorting
Sorting data in a standard grid often requires writing custom dataset re-queries. TSMDBGrid simplifies this via individual column configuration using the SortType property, or globally via the SetSortField method:
// Option A: Set sorting properties directly on specific columns (SMDBGrid1.Columns[1] as TSMDBColumn).SortType := stAscending; (SMDBGrid1.Columns[2] as TSMDBColumn).SortType := stDescending; // Option B: Programmatically sorting by a specific Dataset Field SMDBGrid1.SetSortField(YourFDQuery.FindField(‘OrderNo’), stAscending); Use code with caution. 2. Layout Persistence
End-users frequently request that grid column widths, order, and configurations persist between application runs. Instead of manually reading and writing to INI files or the Registry, TSMDBGrid includes native layout state mechanics.
Save Configuration: Invoke the internal routine or context menu to instantly write the current column state.
Restore Configuration: Dynamically reload column visibility, index positions, and custom sizing instantly during the Form’s OnShow lifecycle. 3. Enhanced Navigation (Enter as Tab)
A classic data-entry request is mapping the behavior of the Enter key to mimic the Tab key, moving focus to the adjacent right cell rather than advancing down a row. TSMDBGrid implements this natively, removing the need to intercept heavy CM_DIALOGKEY or OnKeyDown Windows messaging loops. 📊 TSMDBGrid vs Standard TDBGrid Standard TDBGrid Scalabium TSMDBGrid Boolean Fields Text output (“True”/“False”) Interactive UI Checkboxes Multi-line Headers Single-line only (Truncated) Automatic Word-wrap Titles Column Freezing Not supported natively Natively supported Row Multi-Select Requires Shift/Ctrl combinations Dedicated Selection Checkboxes Context Menu Must be coded manually from scratch Built-in DB actions menu 🚀 Getting Started & Compatibility
The component maintains incredible backwards and forwards compatibility, supporting legacy versions from Delphi 3 all the way up through modern RAD Studio environments like 11 Alexandria, 12 Athens, and 13 Florence. Because it inherits directly from the VCL TDBGrid framework, you can drop it onto a form as a direct replacement without losing existing, persistent column parameters or dataset bindings. Scalabium SMComponent library
Leave a Reply