Write grid columns from the field repository
Adds the columns a cxGrid view, an FDGridProvider TFDGPGridTableView or a TDBGrid lacks for the fields of a repository table; add only, dry run by default.
Read this when a grid of a form should show the fields of its table. drag-lint repo write-grid --dfm <form.dfm> --to <view> --repo <file> prints the columns it would add after the existing ones; --apply or --select writes them with a backup. Nothing existing is changed or deleted. Unbound entries get their handlers; a TDBGrid gets Columns items; banded and layout views get bands / groups (schema 7+). An FDGridProvider TFDGPGridTableView (1.63) gets TFDGPGridColumn items, its table from DescribeKey TABLE= and provider-dialect handler macros.
How to run it
drag-lint repo write-grid --dfm <file.dfm> [--unit <file.pas>] --to <view> [--table <TABLE>] (--repo <file> | --project <project file>) [--columns <names>] [--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> | ||
--columns | <names> | ||
--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 write-grid --dfm <file.dfm> [--unit <file.pas>] --to <view> [--table <TABLE>]
(--repo <file> | --project <project file>) [--columns <names>]
[--apply | --select <id file>] [--dry-run] [--json]
Gives a grid of a form a column for every field and unbound entry of a repository table that the grid does not
show yet (IDE: drag-lint > Field Repository > Write to Grid or Layout...). --to names the grid: a
TcxGridDBTableView, a TcxGridDBBandedTableView, a TcxGridDBLayoutView, an FDGridProvider TFDGPGridTableView
(1.63, see below) or a plain TDBGrid. The table is --table, else the
table of the grid's dataset (UpdateOptions.UpdateTableName, UpdateTableName, TableName), else the table the
repository's DL_GRID_COLUMNS rows of that view name.
What is offered. Every DL_FIELDS_INFO row of the table that is a data field (FIELD_KIND NULL or 1), a
calculated field (2), a lookup field (3), an internal-calculated field (4, 1.65), an aggregate field (5, 1.65) or an
unbound entry (10: a column with no data field, graphic or text, see UNBOUND_KIND).
Add only (owner ruling Q160-5 A). A column the grid already has is never touched and nothing is deleted. A cxGrid
column stands for a row when its DataBinding.FieldName is the field, or its name is the COLUMN_NAME the
repository holds for the row or the name a new column would get; a TDBGrid item when its FieldName is the field.
Every byte of the form outside the new lines stays as it was.
Order. Repository order: the rows the repository holds a DL_GRID_COLUMNS row of this view for come first, by
COLUMN_INDEX (with the stored name, caption, width and editor), then the other rows in the order they were stored.
New columns go after the last existing one.
A new cxGrid column is a TcxGridDBColumn named <view><FIELD> (or the stored COLUMN_NAME; a number is added
when the name is taken) and declared in the form class after the view's columns. It states Caption
(DISPLAY_LABEL), DataBinding.FieldName (fields only), the stored editor (only when another item of the form
already uses that PropertiesClassName, so that the form loads it; else a note says it was left out) and Width
(DISPLAY_WIDTH). Per field kind (1.64): a calculated field's column is read-only (Options.Editing = False; a
TDBGrid item ReadOnly = True); a lookup field's column gets no editor of its own unless the repository stores one
-- the grid gives a column bound to a lookup field its registered lookup editor (TcxLookupComboBoxProperties when the
application uses cxDBLookupComboBox), and a lookup editor bound to a lookup field takes its list, key and result
fields from the field (DevExpress cxDBLookupEdit.pas), so none are written. 1.65: an internal-calculated or
aggregate field's column is read-only like a calculated one (cxGrid Options.Editing = False, TDBGrid ReadOnly = True),
and an aggregate's change has a note (every row shows the same value; a footer summary may suit better); an unbound
graphic / text column is read-only too (Options.Editing = False: it shows drawn or generated content). A data field is as before. An unbound entry with code gets its handlers: OnCustomDrawCell = <column>CustomDrawCell from
GRID_DRAWCELL_BODY and OnGetDisplayText = <column>GetDisplayText from GRID_DISPLAYTEXT_BODY, new methods
whose body is the DLFR region repo handlers keeps current (field macros such as {{QTY}} become the field
component).
A banded column is a TcxGridDBBandedColumn with Position.BandIndex (the stored band Band<n>), ColIndex and RowIndex when not 0, and the other Position.* lines of the stored LAYOUT. A field the repository places in no band (no stored CONTAINER_NAME) is placed (1.62): in the band of the last existing column that has one (Band0 when none; a view with no Bands gets Band0), ColIndex after the last column of row 0 of that band (the columns the same write adds count), and its note says so -- a banded column streamed without a band has no Position.Band and the grid does not show it (the test runner loads both shapes). A band the view lacks is added to Bands from DL_GRID_CONTAINERS (Caption, Width, parent band, other lines), with every band below its index and its parent; existing Bands items stay byte for byte. Columns items with FieldName, Title.Caption and Width. A grid without persistent columns
(it showed every field of its dataset) gets a Columns list, so from then on it shows exactly the columns written:
the plan says so.
Existing columns: --columns (1.62). --columns <names> (comma-separated component names, Columns[i] of a TDBGrid or field names, any case; * = every column) compares those existing columns with the repository row each stands for and lists every property that differs as an UNCHECKED change after the inserts ([id] update uForm.dfm tvOrdersQTY Caption: Quantity -> Qty (unchecked)): Caption (Title.Caption of a TDBGrid; repository CAPTION, else DISPLAY_LABEL), Width (WIDTH, else DISPLAY_WIDTH; not on a layout view), and for a column with a DL_GRID_COLUMNS row its editor -- PropertiesClassName and each Properties.* line (insert / update / delete per line; another class replaces the whole editor: the class row and the new lines require each other) -- and, on a banded view, Position.BandIndex, ColIndex / RowIndex and the other Position.* lines. Strings compare exactly, numbers by value, identifiers / sets ignoring case. --apply alone still writes only the inserts; a --select file writes the property ids it names (all includes them). A property change is blocked in an inherited view, for an editor class no item of the form uses, for a band the view lacks, and when the edit cannot be made (tried on a copy first); a missing unit does not block it. A --select file naming a change without one it requires, or a --columns name the view lacks, is a usage error (exit 2; the message lists the view's columns). Not offered (yet): field-name changes, renames, column order, events, Visible / Options / styles, band / group properties.
Blocked (never applied): an unbound entry on a TDBGrid (TDBGrid has no unbound column); a cxGrid column
without a unit that declares the form class; a view the DFM inherits; a handler name the unit already has; a handler
whose types the interface uses clause lacks (cxGridCustomTableView; for OnCustomDrawCell also cxGraphics and
cxGridTableView); a handler whose code names a field the dataset does not have. A field the dataset's persistent
fields lack gets a note (Write Field Info into Dataset adds it).
Nothing is written without --apply (every change that is not blocked) or --select (exactly the ids in the
file; one id per line, or all; the file must hold the # plan <id> line of the dry run). --dry-run wins over
both. Every changed file (.dfm, .pas) gets a backup beside it: <file>.before-write-dfm-<yyyymmdd-hhnnss>.
The new DFM text is converted by the Delphi reader before anything is written; the test runner also compiles the
written form and LOADS it.
| Exit | Meaning |
|---|---|
| 0 | ok, a dry run and a plan without changes included |
| 1 | a DFM / unit that cannot be read, a view the form does not have or that is no table, banded, layout or TDBGrid view, a repository that is missing, below schema 6, or below schema 7 for a banded / layout view (repo migrate --apply), a plan the --select file does not belong to, a write failure |
| 2 | usage: no --dfm, no --to, no table known, a --select file that is missing, has no plan line or names an unknown or blocked id or a change without one it requires, a --columns name the view does not have |
--json prints one object: verb (write-grid), mode (dry-run / apply / select), plan, form, dfm,
view, class, table, columns[] (the columns the view has after the write: column, index, field,
caption, width, propertiesClass, properties, events[], unbound, new, and for banded / layout views container, rowIndex, colIndex, layout), containers[] (the bands / groups the plan adds: name, kind, index, parent, caption, width, new), changeSet (direction
repo-to-dfm), notes[] (one per change), remarks[], applied, written and backups[]. 1.62: selection[] (the compared columns), propertyChanges[] (id, column, field, property, op, current, repository, source = the one TABLE.COLUMN the value comes from, group = editor:<column> for editor rows, requires[] when the change needs others, blocked, note) and dfmText[] (per changed object: object, class, before[] lines, hunks[] of id, from, to (0-based, inclusive; to = from - 1 inserts), lines[]: applying the hunks of the chosen ids to before gives the text the write makes; a new column has an empty before and one hunk). All three are empty without --columns, and the plan id is then the one 1.61 gave.
IDE. Write to Grid shows these changes in a dialog with three tabs -- All changes (tick / id / column / property / current / repository / source / op / note; blocked rows greyed with the reason as the tip), By column (one page per compared column plus New columns) and DFM text (before / after of the picked object, rebuilt on every tick) -- with Tick all / Untick all, Write N and Cancel; new columns open ticked, property changes unticked.
FDGridProvider view (1.63). --to may name a TFDGPGridTableView (FDGridProvider: a table view whose rows come
from a TFDDataSet or a flat buffer at run time). It is written as a table view, with these differences:
- a new column is a
TFDGPGridColumn(sameCaption,DataBinding.FieldName, editor andWidthlines), declared in the form class like any column; - the view has no design-time dataset, so the table is
--table, else theTABLE=part of itsDescribeKey(TABLE=ORDERS|BLOBS=0|WHERE=, the MicroniteTable key), else the repository'sDL_GRID_COLUMNSrows of the view (rows stored while the view was still aTcxGridDBTableViewcount: ORM3 converted its views keeping the names); no persistent-field note is given; - the field macros of an unbound entry's
GRID_DRAWCELL_BODY/GRID_DISPLAYTEXT_BODYare expanded in the **provider dialect**: a provider row holds values, notTFieldobjects, so{{QTY}}becomesTFDGPGridTableView(Sender).FieldValue(AViewInfo.GridRecord, 'QTY')inOnCustomDrawCellandTFDGPGridTableView(Sender.GridView).FieldValue(ARecord, 'QTY')inOnGetDisplayText(aVariant,Nullwhen the field is absent; works with both sources). The member after the macro is read asTFieldwould read it, Null-safe:
| Macro | Becomes (v = the FieldValue call) |
|---|---|
{{F}}, {{F}}.Value, {{F}}.AsVariant | v |
{{F}}.IsNull | VarIsNull(v) |
{{F}}.AsString, .Text, .DisplayText | VarToStr(v) |
{{F}}.AsInteger / .AsLargeInt / .AsFloat / .AsCurrency / .AsDateTime | (if VarIsNull(v) then 0 else Integer(v)) (Int64, Double, Currency, TDateTime) |
{{F}}.AsBoolean | (if VarIsNull(v) then False else Boolean(v)) |
Blocked (the plan says why): a macro that is written ({{F}} :=, {{F}}.AsString := -- grid events read the row),
any other member (.Clear, .FieldName, ...), a macro naming no field of the table, {{ALIAS.F}} (as for every
target: not before repo compose-sql), and a body that calls VarIsNull / VarToStr in a unit whose interface
uses clause lacks System.Variants. write-grid generates a provider region for a NEW unbound column; 1.64:
repo gen-events takes a TFDGPGridTableView too (same dialect) and adds the stored column event code of bound
columns afterwards.
JSON class is TFDGPGridTableView. Tests: tests\autotest\run_v163_FR3WRITE.ps1 (unit cases PM* / FD*, the CLI on
tests\fixtures\fieldrepo\gridfdgp, and the written form compiled against the FDGridProvider sources, loaded, and its
generated OnGetDisplayText run on a memtable attached to the view).
Not built: event code for bound columns (run repo gen-events after write-grid), a footer summary for an aggregate
field, other vendors' grids.
Tests: tests\autotest\run_v160_FRWRITE.ps1 (unit tests on the bytes, the CLI on a schema-6 repository, banded / layout views, and the
written form compiled and loaded; 1.62: --columns and the placed band-less column) and tests\autotest\run_v162_GRIDPROP.ps1 (the dialog's model: the composed DFM text equals the applied bytes for every tick combination).