Skip to main content

TvxField

TvxField = class(TField)

Example

procedure ScriptEvent(var Value: variant);
begin
if Field.IsNullEmpty then
Field.SetIfEmpty('UNKNOWN');

Value := Field.AsStringTrim;
end;

Usage

TvxField adds Velox null, sentinel, type-test and conversion helpers to live Velox dataset fields through a stateless scripting facade.

Additional Technical Info

TvxField is the Velox scripting facade for a live Delphi dataset field. It inherits the registered TField surface and adds exact tests for null/empty/zero values, conditional setters, field-type groups and convenience conversion properties.

Do not construct or free this class. Velox returns it from field-map context and dataset field lookups; the underlying object is normally a concrete Delphi field such as TStringField, TIntegerField or TDateTimeField.

The PascalScript import exposes thirteen methods and seven read/write properties. It does not register the native constructor.

Facade implementation

Velox applies a static TvxField cast to ordinary TField descendants. TvxField deliberately contains no instance data: source comments record that an earlier stateful design caused access violations because the real object had not been allocated with a TvxField layout. Current helpers operate only through inherited virtual properties and existing field state.

The static cast does not change the object's runtime class. Virtual access such as AsDateTime still dispatches through the actual field descendant; unsupported conversions can raise.

Helper groups

PurposeMembers
Exact nullNull, NotNull
Blank textIsNullEmpty, NotNullEmpty, SetIfEmpty
Null/zero sentinelIsNullZero, NotNullZero, SetIfZero
Conditional null replacementSetIfNull
Hard-coded field groupsIsDateType, IsNumericType, IsStringType
Convenience valuesAsDateTime, AsFloat0, AsInteger0, AsStringTrim, AsInfo
SQL-shaped textAsSQL, AsSQLTrim
Velox explicit-null flagForceNull

The empty and zero helpers are product-defined sentinel rules, not interchangeable null tests. In particular, Boolean false and date/time value zero are zero-like, while string '0' is not.

State, ownership and errors

Every read uses the current record. Every write uses the concrete field's Value, AsString, AsFloat, AsInteger or AsDateTime setter and can require dataset edit state, invoke conversion/validation, mark the record modified or raise. A write does not Post, ApplyUpdates or commit anything by itself.

The owning view/dataset controls lifetime. A retained reference follows cursor movement and becomes invalid when fields are destroyed or the schema is rebuilt. Dataset buffers and field objects are not thread-safe.

Important quirks

  • ForceNull only sets Required := True; it does not clear the field.
  • Date/numeric/string membership is a fixed list and omits some newer or specialised field types.
  • AsInfo has a labelled getter but a raw AsString setter.
  • AsSQL and AsSQLTrim getters quote formatted display text, not a typed parameter value; both setters contain a lossy substring bug and should not be used for round trips.
  • The compiler registration text for IsNumericType contains an extra closing parenthesis. The PascalScript parser ignores the trailing token after the completed return type and the runtime importer binds the method, so the method remains available.

External references

Created 2026-07-15