Generate grid column event handlers from the field repository
Writes stored grid column event code (OnGetDisplayText, OnCustomDrawCell, OnGetDataText, ...) into new handlers of a form; add only, dry run by default.
Read this when the repository holds column event code for a field and a grid view shows that field without the handler. drag-lint repo gen-events --dfm <form.dfm> --to <view> --repo <file> prints the handlers it would add; --apply or --select writes them with a backup of the DFM and the unit. Each handler is a new method COLUMN+Event whose body is a hashed DLFR region; the event is assigned in the DFM. An assigned event is reported, never replaced.
How to run it
drag-lint repo gen-events --dfm <file.dfm> [--unit <file.pas>] --to <view> [--table <TABLE>] (--repo <file> | --project <project file>) [--apply | --select <id file>] [--dry-run] [--json]
Full flag list: repo in the CLI reference.
Flags
| Flag | Argument | Meaning | Default |
|---|---|---|---|
--dfm | <file.dfm> | ||
--unit | <file.pas> | ||
--to | <view> | ||
--table | <TABLE> | ||
--repo | <file> | ||
--project | <project file> | ||
--apply | |||
--select | <id file> | ||
--dry-run | |||
--json |
Where to click
No IDE surface: this feature runs from the CLI (see How to run it).
Details
drag-lint repo gen-events --dfm <file.dfm> [--unit <file.pas>] --to <view> [--table <TABLE>]
(--repo <file> | --project <project file>) [--apply | --select <id file>] [--dry-run] [--json]
Puts the column event code the repository holds for a table into the form: for every column of the grid view --to
whose DataBinding.FieldName is a field with stored code, a NEW handler is written into the form unit and the event is
assigned in the DFM. --to names a TcxGridDBTableView, TcxGridDBBandedTableView, TcxGridDBLayoutView or (1.64)
an FDGridProvider TFDGPGridTableView. The table is --table, else the table of the view's dataset
(UpdateOptions.UpdateTableName, UpdateTableName, TableName; a TFDGPGridTableView: the TABLE= part of its
DescribeKey, as repo write-grid reads it).
FDGridProvider view (1.64). A TFDGPGridTableView is a table view (layout DBTable, the same stored code) whose
columns are TFDGPGridColumn. Its rows hold values, not TField objects, so the field macros are expanded in the
provider dialect of repo write-grid (same member table, Null-safe): {{QTY}} becomes
TFDGPGridTableView(VIEW).FieldValue(RECORD, 'QTY'), where VIEW / RECORD are Sender / AViewInfo.GridRecord in
OnCustomDrawCell, Sender.GridView / Sender.GridView.ViewData.GetRecordByRecordIndex(ARecordIndex) in
OnGetDataText (a record the view does not show gives nil, so Null), and Sender.GridView / ARecord in the
other events. A macro is checked against the table's DL_FIELDS_INFO field names (the view has no design-time
dataset). Blocked in addition: a written macro, a member the dialect lacks, a field the table lacks, and code that
calls VarIsNull / VarToStr in a unit whose interface uses clause lacks System.Variants. Tests:
tests\autotest\run_v164_FDGPEVENTS.ps1 (unit cases FG*, the CLI on tests\fixtures\fieldrepo\eventgen-fdgp, the
written form compiled against the FDGridProvider sources, loaded, and its handlers run on a memtable).
Which code. The layout type follows the view: DBTable, DBBanded or DBLayout. A table view takes
OnGetDisplayText from DL_FIELDS_INFO.GRID_DISPLAYTEXT_BODY, OnCustomDrawCell from GRID_DRAWCELL_BODY, and
every other column event from the DL_LAYOUT_EVENTS rows of layout DBTable with a FIELD_NAME. A banded or layout
view takes every event from DL_LAYOUT_EVENTS rows of its own layout. View events (FIELD_NAME empty) are not
column events and are left out.
Events. OnGetDisplayText, OnCustomDrawCell, OnGetDataText, OnGetProperties, OnGetCellHint (the events
the ORM3 CLIENT forms use on columns). The handler gets the DevExpress parameter list of the event, so the stored code
uses its parameter names (AText, ACanvas, AViewInfo, ADone, ARecordIndex, AProperties, AHintText, ...).
The handler is a published method <column><Event without On>, e.g. tvOrdersQTYGetDisplayText, declared after
the component declarations and implemented before the final end.. Its body is the hashed DLFR <column>.<Event>
region that repo handlers keeps current; field macros such as {{QTY}} become the field component of the view's
dataset (memOrdersQTY).
Add only. An event the column already has is never replaced: the plan prints
NOTE: <column>.<Event> is assigned to <handler> already: not replaced. A second run therefore adds nothing.
Blocked (never applied): no unit, or a unit that does not declare the form class; an event with no known signature;
two stored bodies for one field and event (for example a GRID_DISPLAYTEXT_BODY and a DL_LAYOUT_EVENTS DBTable
row: one body per event in 1.61); a handler name the unit already has; a type unit the interface uses clause lacks
(cxGridCustomTableView; cxGraphics for OnCustomDrawCell; cxEdit for OnGetProperties; System.Types /
Winapi.Windows and Vcl.Controls for OnGetCellHint); code whose macro names a field the dataset does not have.
Writing. The default is a dry run. --apply writes every change that is not blocked; --select <file> exactly
the ids its file names (one per line, or all, with the # plan <id> line of the dry run); --dry-run wins over
both. The new DFM is converted to binary by the Delphi reader before anything is written; the DFM and the unit each
get a backup <file>.before-write-dfm-<timestamp> beside them. Exit 0 ok, 1 form / view / repository (below schema
- / write failure, 2 usage.
JSON (--json): verb, mode, plan, form, dfm, unit, view, class, layout, table,
handlers (id, column, event, handler), changeSet, notes (where each body is stored), remarks,
applied, written, backups.
Not in 1.61: view-level events, event variants (two bodies for one field and event), replacing an assigned handler.
repo write-grid does not call gen-events; run it after write-grid on the same view.