Wątki

[ Pobierz całość w formacie PDF ]
.FocusControl sets focus to the first data-aware control in a form that isassociated with a field.An event handler should call a field s FocusControl methodbefore validating the field.The following code illustrates how to call the FocusControlmethod for the Company field in the Customers table:CustomersCompany.FocusControl;The following table lists some other field component methods and their uses.For acomplete list and detailed information about using each method, see the entries forTField and its descendants in the online VCL Reference.Table 25.6 Selected field component methodsMethod PurposeAssignValue Sets a field value to a specified value using an automatic conversion functionbased on the field s type.Clear Clears the field and sets its value to NULL.GetData Retrieves unformatted data from the field.IsValidChar Determines if a character entered by a user in a data-aware control to set a value isallowed for this field.SetData Assigns unformatted data to this field.Wor k i ng wi t h f i el d c omponent s 25-17 Di s p l a y i n g , c o n v e r t i n g , a n d a c c e s s i n g f i e l d v a l u e sDisplaying, converting, and accessing field valuesData-aware controls such as TDBEdit and TDBGrid automatically display the valuesassociated with field components.If editing is enabled for the dataset and thecontrols, data-aware controls can also send new and changed values to the database.In general, the built-in properties and methods of data-aware controls enable them toconnect to datasets, display values, and make updates without requiring extraprogramming on your part.Use them whenever possible in your databaseapplications.For more information about data-aware control, see Chapter 20,  Usingdata controls.Standard controls can also display and edit database values associated with fieldcomponents.Using standard controls, however, may require additionalprogramming on your part.For example, when using standard controls, yourapplication is responsible for tracking when to update controls because field valueschange.If the dataset has a datasource component, you can use its events to help youdo this.In particular, the OnDataChange event lets you know when you may need toupdate a control s value and the OnStateChange event can help you determine whento enable or disable controls.For more information on these events, see  Respondingto changes mediated by the data source on page 20-4.The following topics discuss how to work with field values so that you can displaythem in standard controls.Displaying field component values in standard controlsAn application can access the value of a dataset column through the Value propertyof a field component.For example, the following OnDataChange event handlerupdates the text in a TEdit control because the value of the CustomersCompany fieldmay have changed:procedure TForm1.CustomersDataChange(Sender: TObject, Field: TField);beginEdit3.Text := CustomersCompany.Value;end;This method works well for string values, but may require additional programmingto handle conversions for other data types.Fortunately, field components have built-in properties for handling conversions.Note You can also use Variants to access and set field values.For more information aboutusing variants to access and set field values, see  Accessing field values with thedefault dataset property on page 25-20.25-18 Dev el oper  s Gui de Di s p l a y i n g , c o n v e r t i n g , a n d a c c e s s i n g f i e l d v a l u e sConverting field valuesConversion properties attempt to convert one data type to another.For example, theAsString property converts numeric and Boolean values to string representations [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • mikr.xlx.pl
  • Powered by MyScript