Menu ▾ ▴

#31 TDatasetHelper.TryFieldAsXxx/FieldAsXxx: optional ErrorHandling parameter

unread
nobody
2026-10-14
2026-10-14
No

Follow-up to [features:#30].

TryFieldAsInteger, TryFieldAsDouble, TryFieldAsExtended, TryFieldAsString and TryFieldAsDate in u_dzDatasetHelpers call the TryVar2Xxx functions, which since [bugs:#63] raise EVariantConvertError for a field value that cannot be converted. The FieldAsXxx(_Fieldname, _Default) overloads are built on them, so they raise in that case too, and a caller has no way to get the Default instead.

They get the same optional parameter as TryVar2Xxx and Var2Xxx, _ErrorHandling: TErrorHandlingEnum = ehRaiseException, and pass it on. With ehNoException the Try functions return False and the FieldAsXxx overloads return the Default for a value that cannot be converted.

An unknown field name keeps raising EDatabaseError regardless of ErrorHandling: that is a programming error, not a value problem.

Notes:

  • The methods are part of IDatasetHelper, so the interface changes too.
  • The doc comments still say the Default is returned for a value that cannot be converted, which has been wrong since [bugs:#63]; they are fixed with this change.
  • TryFieldAsDate depends on TryVar2DateTime, see [bugs:#65].

Related

Bug Reports: #63
Bug Reports: #65
Feature Requests: #30

Discussion


Log in to post a comment.