Skip to content

VCL bridge: make set_text / set_checked data-aware (TDBEdit, TDBMemo, TDBCheckBox) - #3

Closed
doerig wants to merge 2 commits into
GabrielOnDelphi:mainfrom
doerig:feature/db-aware-set-text
Closed

doerig wants to merge 2 commits into
GabrielOnDelphi:mainfrom
doerig:feature/db-aware-set-text

Conversation

@doerig

@doerig doerig commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

set_text on a VCL data-aware control (TDBEdit, TDBMemo, ...) writes Text via RTTI. That only changes the window text: DataLink.Edit never runs (the dataset stays in dsBrowse, TDBEdit even keeps its Windows edit read-only) and DataLink.UpdateRecord never runs, so the value is silently discarded on the next scroll. A user typing into the control gets both through KeyPress and CMExit. Same for set_checked on TDBCheckBox: a direct Checked write never marks the link modified.

Change

  • set_text: when the component has a published DataField <> '' and a DataSource with a DataSet, call DataSet.Edit before the write (entering dsEdit fires DataChange, which would overwrite a value written earlier) and Perform(CM_EXIT) after it (the control's CMExit runs UpdateRecord, then the regular OnExit).
  • set_checked: a data-aware checkbox is toggled through BM_CLICK (synchronous Perform; BN_CLICKED -> Toggle -> DataLink.Edit + Modified) only when the state has to change, then CM_EXIT.
  • Both responses carry dataBound: true|false.
  • Resolved purely via RTTI (DataField -> DataSource -> DataSet -> Edit/CanModify), so the bridge has no Data.DB dependency and non-database apps link nothing extra. FMX untouched.
  • Tool descriptions and AI-INSTRUCTIONS.md updated.

Refusals (same rules as for a typing user, reported as -32005 with the reason)

Control ReadOnly, field not modifiable (read-only/calculated/lookup), dataset CanModify = FALSE, DataSource.AutoEdit = FALSE while not in dsEdit/dsInsert, OnBeforeEdit abort, data-aware control without a writable Text (TDBLookupComboBox, TDBRadioGroup). A dataset the app already put into edit mode is left alone. set_checked re-reads Checked after BM_CLICK (second click for the AllowGrayed step) and fails when the toggle was refused.

Tested

Delphi 13 (37.0), VCL app with TDBMemo bound to a TADODataSet (SQL Server): set_text -> dataBound: true, dataset in dsEdit, field buffer holds the value, form's Save button persisted it, re-read from DB matched. Before the change the same call left the dataset in dsBrowse and the value was lost.

🤖 Generated with Claude Code

doerig and others added 2 commits September 14, 2026 13:36
A plain RTTI write to a TDBEdit / TDBMemo / TDBCheckBox only changes the
window text: the dataset never enters dsEdit and DataLink.UpdateRecord
never runs, so the value is discarded on the next scroll. A typing user
gets both through KeyPress/Toggle (DataLink.Edit) and CMExit
(DataLink.UpdateRecord).

set_text now resolves DataField -> DataSource -> DataSet via RTTI, calls
DataSet.Edit before the write and sends CM_EXIT after it. set_checked
toggles a data-aware checkbox through BM_CLICK (Toggle is protected and is
the only path that marks the link modified) and sends CM_EXIT. Both
responses carry dataBound so the caller can see that the chain ran.

RTTI only, no Data.DB dependency; FMX unchanged. Tool descriptions and
AI-INSTRUCTIONS.md updated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review follow-up on the data-aware set_text / set_checked:

- Go through DataSource.Edit instead of DataSet.Edit so Enabled/AutoEdit
  apply, and refuse up front (-32005 with the reason) what the VCL refuses
  a typing user: control ReadOnly, field not modifiable (read-only,
  calculated, lookup), dataset CanModify = FALSE, AutoEdit = FALSE while
  not in dsEdit/dsInsert. A dataset the app already put into edit mode is
  left alone. Edit exceptions (OnBeforeEdit Abort) are reported, not
  passed on as a bare internal error.
- Check for a writable Text before entering edit mode: TDBLookupComboBox
  (read-only Text) and TDBRadioGroup (Caption fallback) no longer leave
  the dataset in dsEdit with nothing written.
- set_checked: no Edit up front (Toggle does it), HandleNeeded, re-read
  Checked after BM_CLICK, second click for the AllowGrayed step, fail when
  the state did not change.
- Docs: verified controls named (TDBEdit, TDBMemo), refusal rules and the
  BM_CLICK focus side effect documented, TDBComboBox marked untested.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@GabrielOnDelphi

Copy link
Copy Markdown
Owner

Thank you, Martin! Your change is included in main and will ship in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants