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
| Purpose | Members |
|---|---|
| Exact null | Null, NotNull |
| Blank text | IsNullEmpty, NotNullEmpty, SetIfEmpty |
| Null/zero sentinel | IsNullZero, NotNullZero, SetIfZero |
| Conditional null replacement | SetIfNull |
| Hard-coded field groups | IsDateType, IsNumericType, IsStringType |
| Convenience values | AsDateTime, AsFloat0, AsInteger0, AsStringTrim, AsInfo |
| SQL-shaped text | AsSQL, AsSQLTrim |
| Velox explicit-null flag | ForceNull |
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
ForceNullonly setsRequired := True; it does not clear the field.- Date/numeric/string membership is a fixed list and omits some newer or specialised field types.
AsInfohas a labelled getter but a rawAsStringsetter.AsSQLandAsSQLTrimgetters 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
IsNumericTypecontains 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
- Embarcadero DocWiki:
TFielddescribes the actual field hierarchy, conversions and null defaults used beneath the facade. - Free Pascal:
TFieldprovides compatible field-model context; Velox runs against Delphi's implementation.