15th chapter-Application and programming of data access Parts (III.) (2)

Source: Internet
Author: User
Tags integer numeric

The properties in table 15.6 are not owned by all types of field parts, such as a Tstringfield type of field part that does not have currency, MaxValue, MinValue, and DisplayFormat properties. A field part of a Tfloatfield type does not have the size attribute.

For a Boolean property, double-click the property in the object inspector in the design process to switch back and forth between true and false, and other properties require the user to enter the property value or select the property value from the Drop-down list box. All properties can be set through program code. Most properties can be set independently, and only Displayformat,editformat and Editmask are interconnected. When setting their property values, be sure to coordinate with each other.

Use the Editmask property to set the editing mode for the field:

Set a certain Editmask property value for the field part, and when you edit the field value for the field, the user can only edit or enter the field value based on the edit mode set by Editmask. You can do this manually or with the input mode editor when you set property values for the Editmask property, and when you set the Editmask property for a field part, double-click the Editmask property to open the Input mode editor (input Mask Editor). For example, when setting edit mode for the Phone field in the Customer.db table, first select the Table1phone Field object in Object inspector that corresponds to the Phone field, and then double-click the Editmask property to open the input mode editor.

field Input Mode Editor

You can select an input mode in the field input mode edit, and enter the field value in the Testinput edit box to verify.

Because the field part of the Tstringfield type does not have a DisplayFormat property, you can use the Editmask property as the DisplayFormat property.

To set the display and editing format for a field:

Delphi itself provides a routine for certain types of field objects to set their display and editing formats, and specifies the default value for the DisplayFormat and Editformat properties of the field part, for example, for a field part of the Tfloatfield type corresponding to a floating-point numeric field. And when the currency property of the field part is set to true, the field value 1234.56 is displayed in $1234.56, and the edit format is 1234.56. Table 15.7 is Delphi provides routines for setting field display and editing formats.

Table 15.7 field Format routines

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The Field object used by the routine name

─────────────────────────────

Formatfloat Tfloatfield,tcurrencyfield

FormatDateTime Tdatefield,ttimefield,tdatetimefield

Formatinteger Tintegerfield,tsmallintfield,twordfield

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

These routines for the display and editing of date-time types, numeric types, and currency fields are formatted according to the international format for the type of field, and the user can set the DisplayFormat and Editformat properties of the field parts. To set the format for your own use, and you can write code for the Ongettext and Onsettext events for the field objects to set the display and editing format for the fields.

15.6.1.2 Field component events and their applications

The events that the field parts often need to handle are shown in table 15.8

Table 15.8 event for a field part

━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Event name use

────────────────────────────

OnChange the event when the field value of the field part is changed

Ongettext When a field part gets the field value, the event is triggered

Onsettext When a field part is set to a field value, the event is triggered

Onvalidata when a word value is modified or a new field value is inserted, the value of the field

When validation is performed, the event is triggered

━━━━━━━━━━━━━━━━━━━━━━━━━━━━

When the user wants to set the display and editing format of the field, you can write the Ongettext event and the Onsettext event process to achieve the display and edit format of the Set field.

15.6.1.3 Field Component type conversion functions and their use

The field part has some types of intrinsic functions for converting field values, and for different field types, these conversion functions are not the same, and table 15.9 summarizes the roles of different types of fields and transformation functions.

Table 15.9 Conversion functions for field parts

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Field type asstring asinteger asfloat asdatetime Asboolean

────────────────────────────────────

Convert Tstringfield into integer if converted to a date convert to a cloth type

Stringg (if able to convert) is converted to (if able to convert)

────────────────────────────────────

Tintegerfield

Tsmallfield character-type integer floating-point type does not allow conversions

Twordfield

────────────────────────────────────

Tfloatfield

Tcurrencyfield string rounded to integer floating-point type does not allow

Tbcdfield

────────────────────────────────────

Tdatefield

Tdatetimefield string does not allow floating-point number date type not allowed

Ttimefield

────────────────────────────────────

Tbooleanfield conversion to time does not allow Boolean type not allowed

or false

────────────────────────────────────

Tbytesfield

Tvarbytesfield string not allowed not allowed not allowed

Tblobfield

────────────────────────────────────

Tmemofield binary does not allow disallow not allowed

Tgraphilfield Field

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

These conversion functions can be used in any expression related to a field part, as long as the data types that are allowed for conversion in table 15.9 are used as properties of the field part, and they can appear on both sides of the assignment statement. For example, the following program code converts field values of a field part Tablemyfield to a string type of data and assigns it to the Text property of the edit box Edit1:

Edit1.text: = tablemyfield.asstring;

The following code, in turn, assigns the Text property value of the edit box part Edit1 to the field as a string Tablemyfield,tablemyfield to accept the string by asstring and convert it to its own data type.

Tablemyfield.asstring: =edit1.text;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.