Delphi-RAG-Lint

drag-lint help

Datasets of an inherited form or data module

Since: 1.56.0-alpha

repo read-dfm follows link sources, lookups and grid datasets, and inherited datasets, into the ancestor DFM, and finds modules of used units in the project.

Read this when repo read-dfm reports a memory table or a lookup as unresolved although its source is a dataset of an inherited data module. drag-lint finds the ancestor class in the unit beside the DFM and reads the one DFM of the same folder that has it, also for inherited datasets; a module of a used unit elsewhere in the project folder or on the project's unit search path is found too, and an ancestor form in another folder. What it cannot follow is a warning that names the reason; nothing is picked. AttachTable(X.Table) links to dataset X.

How to run it

drag-lint repo read-dfm --dfm <file.dfm>[;...] [--dataset <Name>] --direction dfm-to-repo (--repo <file> | --project <project file>) [--apply | --select <id file>] [--dry-run] [--json] [--db <project index>] (the persistent fields of a form's datasets as a change set: data, calc, lookup, internal-calc and aggregate fields, captions / formats / widths, lookup wiring, OnCalcFields code as CALC_BODY with {{FIELD}} component macros, OnGetText / OnSetText / OnValidate / OnChange code and OnGetDisplayText / OnCustomDrawCell code of TcxGridDBTableView columns, the column order of table and banded grid views and each column's in-place editor, PropertiesClassName and its Properties.* lines as the form has them (DL_GRID_COLUMNS; the editor needs schema 5, an older repository gets a warning); code in generated DLFR regions (hashed or volatile) is not read back; needs a schema-4 repository or later (schema 7: also LOOKUP_DATASET, LOOKUP_CACHE, FIELD_PROPS of non-data fields); text or binary DFM, BDE or FireDAC; the table comes from UpdateTableName, TableName or a one-table SELECT, a join gives every field its own table, a calc reading several tables goes to the child end with {{ALIAS.FIELD}} inputs (alias = the table name) and DL_FIELD_INPUTS / DL_RELATIONS rows (the form's ON / WHERE joins choose the path; a join on a parent key with no FK is offered as a FORM relation, unchecked), a memory table takes the source of its AttachedTo or of a literal AttachTable / CloneCursor / CopyDataSet / CopyData / AppendData / Data := (cycle or two sources = unresolved), a link source, a lookup dataset and a grid's dataset that the module only inherits are read from the DFM of the ancestor form / data module (ancestor class from the unit beside the DFM, the one DFM of the same folder with that root class; not found or two = a warning, nothing picked), AttachTable(X.Table, ...) links to dataset X, an inherited dataset of an inherited form or module is itself read from the ancestor DFM (handler code from the unit of the form that states it), a module dmX.tblY that is not in the form's folder is found through the units the form's unit uses, in the project folder (nearest folder with a .dpr/.dproj/.dpk, up to three levels up) and below it, folders starting with __ or . left out, two candidates = a warning, nothing picked, anything else is listed as UNRESOLVED; with --dataset --json also lists the persistent fields and the repository fields of the table; --db <project index> = the index the lineage facts are read from: a persistent data field without a table column that code fills from other fields is proposed as insert DL_FIELDS_INFO T|F: derived(direct|aggregate); inputs {{..}} + insert DL_FIELD_INPUTS T|F||ALIAS, all unchecked (write them with --select), without it one warning lineage: skipped (no index); no --apply = dry run; exit 1 read / apply failure, 2 usage or a bad --select file)

Full flag list: repo in the CLI reference.

Where to click

No IDE surface: this feature runs from the CLI (see How to run it).

Details

drag-lint repo read-dfm follows a dataset name into the DFM of the ancestor form or data module. Nothing new is typed: the same command reads more.

drag-lint repo read-dfm --dfm <form.dfm>[;...] --direction dfm-to-repo (--repo <file> | --project <project file>)

Why

A DFM whose first line is inherited dmOrders: TdmOrders holds only what the descendant changes. The table name, the SQL and the persistent fields of an inherited dataset are in the DFM of the ancestor class. Before 1.56 a memory table filled from such a dataset, and a lookup field that names one, were reported as unresolved:

dataset uForm.dfm memOrders (TFDMemTable) -> UNRESOLVED (linked to dmDerived.tblOrders (CopyDataSet), which has no table: ...)

Now the dataset is read as the form has it at run time:

dataset uForm.dfm memOrders (TFDMemTable) -> ORDERS (via CopyDataSet dmDerived.tblOrders)
warning: uDerived.dfm tblOrders: read from the ancestor uBase.dfm

Where it applies

PlaceWhat is followed
the source of a link (AttachedTo, AttachTable, CloneCursor, CopyDataSet, CopyData, AppendData, Data :=)a dataset the module only inherits, or does not mention at all
LookupDataSet of a lookup fieldthe same
the dataset behind the data source of a grid viewthe same

The inherited dataset of an inherited form itself is read the same way (1.56 GCR-2): the line dataset PathToData.dfm tblOSublot (TFDTable) -> OSUBLOT: ... now has the ancestor's table and fields, then the fields the descendant adds. Its handler code is read where it is written: the calc bodies from the unit of the form whose DFM states OnCalcFields, the events of a field from the unit of the form whose DFM declares the field. Only when no ancestor is found the line still ends in UNRESOLVED (... (inherited: its own properties are in the ancestor's DFM)).

How the ancestor is found

  1. The first object line of the DFM says inherited Name: TClass (text or binary DFM).
  2. The unit beside the DFM declares TClass = class(TAncestor). Comments are not read; a unit qualifier and type arguments are dropped.
  3. The ancestor DFM is the ONE DFM of the same folder whose root class is TAncestor. Its own ancestor is followed the same way.

What the descendant states wins (TableName, UpdateOptions.UpdateTableName, SQL, OnCalcFields, AttachedTo); the fields are the ancestor's, then the fields the descendant adds.

What is not followed (each is a warning, nothing is picked)

WarningMeaning
X.dfm: inherited from an ancestor form, but no unit beside the DFM names it: ancestor not readno X.pas next to the DFM
X.dfm: X.pas declares no ancestor class for TClass: ancestor not readthe class declaration was not found in the unit
X.dfm: no DFM of this folder has the ancestor class TAncestor: ancestor not readthe ancestor form is in another folder, or has no DFM
X.dfm: 2 DFMs of this folder have the ancestor class TAncestor: ancestor not reada copy of the ancestor DFM is in the folder

Known limits: a property an inherited FIELD overrides (for example DisplayLabel) is not applied to the ancestor's field; a property the descendant resets to an empty value reads as the ancestor's value; a link in the ANCESTOR's unit code is not followed for the descendant; the calc bodies of an inherited dataset that is a JOIN are looked for in the descendant's unit only.

A module in another folder (1.56 GCR-2)

dmX.tblY in a link, a LookupDataSet or a grid's data source names a module. The module is first looked for in the folder of the form (one DFM with the root object dmX). When that folder has none:

  1. The form's unit must USE the module's unit (interface or implementation uses; comments are not read).
  2. The DFM of that unit (uMod.dfm for uses uMod) is looked for in the project folder and every folder below it. The project folder is the nearest folder, from the form's folder up to three levels above it, that holds a .dpr, .dproj or .dpk; without one it is the form's own folder. Folders whose name starts with __ or . (__history, __recovery, backup copies, .git) are not searched.
  3. Exactly one such DFM with the root object dmX is the module. Two give the warning X.dfm: 2 DFMs of the used unit uMod have the root dmX (dm\uMod.dfm, old\uMod.dfm): module not read and nothing is picked.

A module whose unit the form does not use is not found: the dataset stays `UNRESOLVED (linked to dmX.tblY (...), which is no dataset of the form or of a module beside it)`.

Search path, ancestor in another folder, inherited code (1.56 GCR-3)

  • Search path. When the project folder holds no DFM of the used unit, the DCC_UnitSearchPath of the .dproj found as above (the base groups and the active configuration's group) is searched too: every entry without an unresolved $(...) macro is a folder ($(DCC_UnitSearchPath) itself is skipped), and <uUnit>.dfm is looked for flat in it. Hits join the same candidate list: two candidates are still a warning and nothing is picked.
  • Ancestor form in another folder. When the form's own folder holds no DFM with the ancestor class, the ancestor is looked for by its class among the DFMs of the module finder (project folder, search path); the own folder still wins.
  • Inherited code. For a component the form inherits, the link sources, the field writes and the calc bodies are read from the units of the ancestor chain (the unit of the form that states them), not only from the descendant's unit; a calc body of an inherited JOIN dataset is looked for in the same chain.
  • Write side. repo write-dfm no longer proposes removing a derived field (a DL_FIELDS_INFO row with DERIVED_KIND) that the selection leaves out; derived rows are not table data.

AttachTable(X.Table, ...)

FireDAC's AttachTable takes the storage of a dataset, so memA.AttachTable(tblB.Table, nil) links memA to the dataset tblB (and dm.tblB.Table to dm.tblB). Before 1.56 tblB was taken for a module name and the link was unresolved. No other call reads .Table.

See also


All features | CLI reference | IDE menus