Type

TField = class(TComponent) publ ic

142 It would also have been possible to customize the field definition to field mapping by modifying the CreateFi el d method of the TFi el dDef class, if only the method was virtual in the base class!

property AsExtended: Extended read GetAsExtended write SetAsExtended; property AsAnsiString: AnsiString read GetAsAnsiString write SetAsAnsiString; property AsBytes: TBytes read GetAsBytes write SetAsBytes;

Notice despite the introduction of Unicode, database mapping didn't change, because by default databases consider as string an AnsiString text, and not a Unicode-enabled text, for which you need to use a specific field type. That's why the classic ftString type, managed by the TStringField class, is still based on AnsiString. If you want to have Unicode strings in your database you need to use the ftWideString type and the corresponding TWideStringField class, exactly like in past versions of Delphi. I've already highlighted in the section "Field Types and Strings" how the two string field types handle internal values.

There are also a few new TField derived classes, for handling some of the new field types. Here is the first line of the declaration of these new classes, so you can see which is the base class: type

TLongWordField = class(TNumericField) TShortintField = class(TIntegerField) TByteField = class(TIntegerField) TUnsignedAutoIncField = class(TLongWordField) TExtendedField = class(TNumericField)

With these new classes, the hierarchy of the TField classes defined in the DB unit becomes even bigger. To help you get a full picture, I've provided a complete class tree below :

TField

TStringField

TWideStringField TGuidField TNumericField TIntegerField TAutoIncField TSmallintField TShortintField TByteField TWordField TLongWordField

TUnsignedAutoIncField TLargeintField // Int64 TFloatField

TCurrencyField

TExtendedField TBCDField TFMTBCDField TBooleanField TDateTimeField TDateField TTimeField TSQLTimeStampField TBinaryField TBytesField

TVarBytesField TBlobField TMemoField

TWideMemoField // widestring memo TGraphicField TObjectField

TADTField // Abstract Data Type TArrayField TDataSetField TReferenceField TVariantField TInterfaceField

TIDispatchField TAggregateField

BLOB fields Considered ANSI

Most field types are fully compatible with past versions of Delphi. This is particularly true for string types, despite the new UnicodeString support, because fields managing ANSI strings and wide strings were and are still different. Similarly, memo fields holding ANSI or Unicode strings are mapped to the separate TMemoField and TWideMemoField field classes. The only potential pitfall could arise with generic BLOB field used to store string-based information. When accessing a TBlobField object as a string, how should Delphi 2009 consider the data? Once more, the decision was to favor backwards compatibility, so the string data within a BLOB field is considered to be ANSI based as in past versions of Delphi. You should use TWideMemoField for Unicode data in a BLOB as suggested by this comment in the GetAsString method of the TBlobField class:

/// For backwards compatibility, read untyped data as Ansi. // Use TWideMemoField for blobs associated with Unicode // string data.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment