Delphi-RAG-Lint

drag-lint help

Field repository: adopt ORM regions

Since: 1.65.0-alpha

Wraps the generated but unmarked code of existing ORM units in hashed DB-RAD A- regions, byte for byte, so the ORM redo can regenerate it.

Read this before an ORM redo of units that carry few region markers (ORM3 SERVER / CLIENT). Only members that match the generator are marked -- also under six named legacy forms of older generators (T3); hand-edited ones are listed, or marked so they read hand-edited.

How to run it

Full flag list: repo in the CLI reference.

Flags

FlagArgumentMeaningDefault
--repo<file>
--project<project file>
--code-dir<folder>
--server-dir<folder>
--client-dir<folder>
--table<T,...>
--include-edited
--json
--apply
--no-backup

Where to click

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

Details

*Since 1.65. The --json plan also covers gen-orm, update-orm, gen-dataservice and upgrade-orm-headers.*

Why

repo update-orm rewrites only the DB-RAD <id> regions of an ORM unit. In the ORM3 SERVER and CLIENT units about 90 % of the generated code (the class declaration, the constructor, EnsureQueriesPrepared, NextID, Load, Save, ...) carries no region marker, so a region-only tool cannot redo it. adopt-regions puts the markers in, without changing one byte of the code.

What it does

For every table of the repository (or --table), it reads i<T>.PAS / u<T>.PAS (--code-dir), u<T>_SERVER.PAS (--server-dir) and u<T>_CLIENT.PAS (--client-dir), generates what the generator writes for the same unit (for the data services both the TableTools "fat" form and the 1.59 thin form) and compares member by member:

  • a member is a T... = class / interface / record declaration of the interface section, or a routine of the implementation section (header in column 1 up to the next end; in column 1);
  • the comparison ignores whitespace, drag-lint:auto doc blocks and the interface GUID; a region nested in the member (DB-RAD 8 inside Load) is compared by its id only, so update-orm can keep rewriting it;
  • a member that equals the generated one is wrapped:
{$REGION 'DB-RAD A-NEXTID hash=0123456789abcdef'}
function TDataService_TOOLDEF_SERVER.NextID: Int64; // 1
...
end;
{$ENDREGION 'DB-RAD A-NEXTID'}

The id is A- plus the member name (-2, -3 for an overload). The hash is the whitespace-blind hash update-orm uses, taken over the member with each nested region replaced by its id.

Left unmarked and listed:

keep <member>: ...why
n line(s) the generator does not writethe member was edited by hand, or by an older generator in a way no legacy form covers
inside the region '<name>'it sits in a hand region (MicStream prototype ...)
a region marker crosses the membera region starts in it and ends outside, or the other way
inside or across a conditional{$IFDEF} around or through it

Legacy forms (1.65, OrmLegacyForm)

Units written by an OLDER generator (TableTools, the first DL ports) differ from today's generator in fixed ways that change nothing the code does. A member that fails the strict comparison is compared once more with these named equivalences applied to both sides; equal there, it is adopted with its own hash (it reads intact, not hand-edited) and the plan names the forms it needed (; legacy forms: ... in the text, legacy_forms in --json):

formwhat compares equal
autodoc-linesdrag-lint autodoc doc lines (<!-- drag-lint:auto ... --> elements with their continuation lines, an emptied <remarks> pair); a hand doc line still differs
identifier-caseidentifiers and keywords in any case (Boolean = boolean); strings and comments keep their case
param-p-prefixa parameter pX and X (pThreadStorage = ThreadStorage, pObj = Obj), unless X is another identifier in the parameter's scope
end-tail-commentend; // procedure (also function, constructor, destructor, try, try/except, try/finally, else, if, begin, case, for, while, with) and end;
dataservice-field-namesQRYLoad / QRYSave / CmdNextID and FQryLoad / FQrySave / FCmdNextID, unless the member names both
inject-attribute[Spring.Container.Common.Inject], [Inject] and [InjectAttribute]

Never a fuzzy match: any other difference (a statement, an argument, a string, a hand comment, a hand doc line) keeps the member. Measured on a copy of ORM3 (547 units, 2026-12-02), strict mode before / after the legacy forms: SERVER 1,064 / 37,889 lines, CLIENT 5,634 / 23,634, OBJECTS 3,854 / 8,061 (3,485 regions, 818 members kept); marker-stripped text identical in 547/547 units; update-orm REFUSED 0 / 0. What stays kept on SERVER is real generator drift (Load closes its query in a finally, Save accepts RowsAffected >= 1, PrepareSaveQuery sets the update transaction): those members are regenerated by an explicit --include-edited / --overwrite-edited decision only.

Members the generator does not write at all are counted as hand members. A member already inside a DB-RAD A- region or a numbered ORM region is skipped silently, so a second run changes nothing.

--include-edited

Adopts the hand-edited members too, but writes the hash of the generated body on their start marker. The body does not match that hash, so every tool that applies the update-orm hash rule reads the region as hand-edited and leaves it alone unless --overwrite-edited names it. Measured on a copy of ORM3 (2026-12-02): strict mode adopts 37,889 SERVER / 23,634 CLIENT / 8,061 OBJECTS lines with the legacy forms (1,064 / 5,634 / 3,854 before them); with --include-edited 62,024 / 23,634 / 18,914.

Refused units

A unit is left unchanged and listed as REFUSED when it holds a byte above 127, a comment or string left open, regions that do not nest, or markers update-orm refuses. A dry run still exits 0; --apply exits 1 and writes the other units.

Usage

drag-lint repo adopt-regions (--repo <file> | --project <project file>) [--code-dir <folder>] [--server-dir <folder>]
  [--client-dir <folder>] [--table <T,...>] [--include-edited] [--json] [--apply [--no-backup]]

Without --apply it is a dry run: the plan and a diff per unit. --apply writes 7-bit ASCII with the unit's own line ends and copies each unit to <file>.BCK<n> first (unless --no-backup). Removing the inserted marker lines always gives the old file back.

The JSON plan (T7)

--json prints one document for adopt-regions and for the other ORM generator verbs:

{"verb":"adopt-regions","apply":false,
 "units":[{"file":"...uTOOLDEF_SERVER.PAS","kind":"changed","regions":[{"id":"A-NEXTID","differing_lines":41}],
           "uses":[],"diff":"--- ...","adopted":[{"id":"A-NEXTID","member":"...NextID","first_line":449,
           "last_line":489,"edited":false,"differing_lines":0,
           "legacy_forms":["identifier-case","end-tail-comment","dataservice-field-names"]}],"kept":[...],"hand_members":[...]}],
 "skipped":[{"text":"...: REFUSED, ...","refused":true}],
 "summary":{"new":0,"changed":1,"unchanged":0,"skipped":0,"refused":0,"written":0,"adopted":2,"kept":9}}

For adopt-regions, regions[].differing_lines is the number of lines the region wraps. update-orm fills regions with the regions whose body changes and uses with its uses +X / -X lines. diff is present on a dry run only.

Finding adopted regions

drag-lint query regions --region "DB-RAD A-*" --db <db> (1.65) lists the indexed symbols per adopted region.


All features | CLI reference | IDE menus