Read grid columns into the field repository
Read the columns of every TcxGridDBTableView and TDBGrid of a form, and its unbound columns, into the field repository.
Read this when the grids of a form should be remembered by the field repository. drag-lint repo read-grid --dfm <form.dfm> --repo <file> reads every TcxGridDBTableView, banded, layout view and TDBGrid of the form (or one with --from) and prints the change set that stores their columns in DL_GRID_COLUMNS: caption, field, width, editor class, Properties lines and column event names. A column with no field, or a field the dataset lacks, becomes an unbound graphic or text entry of the table. --apply or --select writes the changes after a backup. --json adds column placement and view containers.
How to run it
drag-lint repo read-grid --dfm <file.dfm> [--unit <file.pas>] [--from <view>] (--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> | ||
--from | <view> | ||
--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 read-grid --dfm <file.dfm> [--unit <file.pas>] [--from <view>]
(--repo <file> | --project <project file>)
[--apply | --select <id file>] [--dry-run] [--json]
Reads the columns of the grids of ONE form into the field repository. Without --from it reads every
TcxGridDBTableView and every plain TDBGrid of the form (IDE: **Field Repository > Read from All Grids on This
Form); --from <view> reads that one view or grid (IDE: **Field Repository > Read from Grid or Layout).
Banded, card and layout views are not read in 1.60 (a warning names them; --from on one is exit 1). A view inside a
frame instance is read from the frame's own DFM.
FDGridProvider view (1.64). A TFDGPGridTableView is read like a TcxGridDBTableView (its TFDGPGridColumn
children; stored with VIEW_CLASS TcxGridDBTableView, the class repo write-grid reads back for an FDGP view).
It has no design-time dataset, so its table is the TABLE= part of its DescribeKey (TABLE=ORDERS|BLOBS=0|WHERE=)
and a column is unbound only when it has no DataBinding.FieldName or the repository table lacks the field. Tests:
tests\fieldrepo\GridReadTests.dpr cases FG1-FG4 (fixture tests\fixtures\fieldrepo\gridfdgp).
Per column the repository keeps (table DL_GRID_COLUMNS, repository schema 6):
| Cell | TcxGridDBTableView column | TDBGrid column |
|---|---|---|
| COLUMN_NAME | the column's component name | Columns[i] (a TColumn has no name) |
| FIELD_NAME | DataBinding.FieldName | FieldName |
| CAPTION | Caption | Title.Caption |
| WIDTH | Width (0 / NULL = not stated) | Width |
| PROPERTIES_CLASS_NAME, PROPERTIES | PropertiesClassName and the Properties.* lines | none |
| EVENT_NAMES | Event=Handler per line: OnGetDisplayText, OnCustomDrawCell, Properties.OnChange, ... | none |
| VIEW_CLASS, COLUMN_INDEX, TABLE_NAME | the view class, the DFM order, the table of the view's dataset | same |
Only the event NAMES are read; the handler code stays in the unit (code bodies are 1.61). --unit is accepted and
not read.
Unbound columns. A column with no field, or with a field its dataset does not have (the dataset's persistent
fields in the DFM; a dataset without persistent fields asks the repository's fields of the table), shows no data
field: a picture or a generated text. It becomes an unbound entry of the view's table, a DL_FIELDS_INFO row of
FIELD_KIND 10, kind graphic when the column has OnCustomDrawCell, else text. Its name is the field the column
names, else the column name without the view name in front (tvOrdersSTATUS in tvOrders -> STATUS). The entry is
reusable by every grid of that table (Write to Grid or Layout offers it). An entry that exists is never changed. A
view whose dataset has no repository table stores its columns but no entry (a warning says so).
Which table. The table of a dataset is found the way repo read-dfm finds it (UpdateOptions.UpdateTableName,
TableName, the FROM of the SQL, links to other datasets).
Change set and writing. The output is a change set, direction dfm-to-repo: an insert per new column (and per
new unbound entry), an update per changed cell, an UNCHECKED delete per stored column the view no longer has.
Nothing is written without --apply (every checked change) or --select (exactly the ids in the file); --dry-run
wins over both. Before the first write the repository is copied to <repo>.before-read-grid-<yyyymmdd-hhnnss>.
A second read of an unchanged form plans no change.
The plan id. The output has a # plan <id> line ("plan" in JSON). A --select file must hold that line, then
one id per line or all; no plan line, another plan, an unknown or blocked id is exit 2 and nothing is written.
Schema. The repository must be schema 6; an older one is exit 1 with "run repo migrate --apply".
Exit codes: 0 ok (a dry run and "no changes" included); 1 a missing repository or DFM, a DFM that cannot be read, a
--from view that is missing or not a TcxGridDBTableView / TDBGrid, schema below 6, a failed write; 2 usage (no
--dfm) or a bad --select file.
--json prints ONE object: verb, mode (dry-run / apply / select), plan, form, dfm, views[]
(view, class, dataset, table, columns[] with column, index, field, caption, width,
propertiesClass, properties, events[] {event, handler}, unbound = "" / graphic / text), changeSet
(as every repository change set), applied, written, backups[], warnings[].
Example:
drag-lint repo read-grid --dfm uOrders.dfm --repo fields.dlrepo
view tvOrders (TcxGridDBTableView) dataset memOrders -> ORDERS: 4 columns
[0] tvOrdersQTY field QTY
[1] tvOrdersNOTE field NOTE
[2] tvOrdersSTATUS field STATUS (unbound text)
[3] tvOrdersIMG field IMG (unbound graphic)
# plan 3f0c9a2b7d1e4c55
direction dfm-to-repo, 6 changes, 0 blocked, 0 unchecked
[1] insert DL_GRID_COLUMNS frmOrders|tvOrders|tvOrdersQTY: -> TABLE_NAME=ORDERS; FIELD_NAME=QTY; ...
...
dry run: nothing written (add --apply, or --select <file> with the # plan line and the ids, to write)
Related: repo copy-grid (columns and events from one view to another view of the same form), Field Repository forms.