-
7:
کد:
Refreshing data
The Refresh method for a dataset flushes local buffers and re-fetches data for an open dataset. You can use this method to update the display in data-aware controls if you think that the underlying data has changed because other applications have simultaneous access to the data used in your application. If you are using cached updates, before you refresh the dataset you must apply any updates the dataset has currently cached.
Refreshing can sometimes lead to unexpected results. For example, if a user is viewing a record deleted by another application, then the record disappears the moment your application calls Refresh. Data can also appear to change if another user changes a record after you originally fetched the data and before you call Refresh.
Enabling mouse, keyboard, and timer events
The Enabled property of a data control determines whether it responds to mouse, keyboard, or timer events, and passes information to its data source. The default setting for this property is True.
To prevent mouse, keyboard, or timer events from reaching a data control, set its Enabled property to False. When Enabled is False, the data source that connects the control to its dataset does not receive information from the data control. The data control continues to display data, but the text displayed in the control is dimmed.
-
8:
کد:
Choosing how to organize the data
When you build the user interface for your database application, you have choices to make about how you want to organize the display of information and the controls that manipulate that information.
One of the first decisions to make is whether you want to display a single record at a time, or multiple records.
In addition, you will want to add controls to navigate and manipulate records. The TDBNavigator control provides built-in support for many of the functions you may want to perform.
Displaying data as labels
TDBText is a read-only control similar to the TLabel component on the Standard page of the Component palette. A TDBText control is useful when you want to provide display-only data on a form that allows user input in other controls. For example, suppose a form is created around the fields in a customer list table, and that once the user enters a street address, city, and state or province information in the form, you use a dynamic lookup to automatically determine the zip code field from a separate table. A TDBText component tied to the zip code table could be used to display the zip code field that matches the address entered by the user.
TDBText gets the text it displays from a specified field in the current record of a dataset. Because TDBText gets its text from a dataset, the text it displays is dynamic--the text changes as the user navigates the database table. Therefore you cannot specify the display text of TDBText at design time as you can with TLabel.
Note
When you place a TDBText component on a form, make sure its AutoSize property is True (the default) to ensure that the control resizes itself as necessary to display data of varying widths. If AutoSize is False, and the control is too small, data display is clipped.
-
9:
کد:
Displaying and editing graphics fields in an image control
TDBImage is a data-aware control that displays graphics contained in BLOB fields.
By default, TDBImage permits a user to edit a graphics image by cutting and pasting to and from the Clipboard using the CutToClipboard, CopyToClipboard, and PasteFromClipboard methods. You can, instead, supply your own editing methods attached to the event handlers for the control.
By default, an image control displays as much of a graphic as fits in the control, cropping the image if it is too big. You can set the Stretch property to True to resize the graphic to fit within an image control as it is resized.
Because the TDBImage can display large amounts of data, it can take time to populate the display at runtime. To reduce the time it takes scroll through data records, TDBImage has an AutoDisplay property that controls whether the accessed data should automatically displayed. If you set AutoDisplay to False, TDBImage displays the field name rather than actual data. Double-click inside the control to view the actual data.
-
10:
کد:
Handling Boolean field values with check boxes
TDBCheckBox is a data-aware check box control. It can be used to set the values of Boolean fields in a dataset. For example, a customer invoice form might have a check box control that when checked indicates the customer is tax-exempt, and when unchecked indicates that the customer is not tax-exempt.
The data-aware check box control manages its checked or unchecked state by comparing the value of the current field to the contents of ValueChecked and ValueUnchecked properties. If the field value matches the ValueChecked property, the control is checked. Otherwise, if the field matches the ValueUnchecked property, the control is unchecked.
Note
The values in ValueChecked and ValueUnchecked cannot be identical.
Set the ValueChecked property to a value the control should post to the database if the control is checked when the user moves to another record. By default, this value is set to "true," but you can make it any alphanumeric value appropriate to your needs. You can also enter a semicolon-delimited list of items as the value of ValueChecked. If any of the items matches the contents of that field in the current record, the check box is checked. For example, you can specify a ValueChecked string like:
DBCheckBox1.ValueChecked := 'True;Yes;On';
If the field for the current record contains values of "true," "Yes," or "On," then the check box is checked. Comparison of the field to ValueChecked strings is case-insensitive. If a user checks a box for which there are multiple ValueChecked strings, the first string is the value that is posted to the database.
Set the ValueUnchecked property to a value the control should post to the database if the control is not checked when the user moves to another record. By default, this value is set to "false," but you can make it any alphanumeric value appropriate to your needs. You can also enter a semicolon-delimited list of items as the value of ValueUnchecked. If any of the items matches the contents of that field in the current record, the check box is unchecked.
A data-aware check box is disabled whenever the field for the current record does not contain one of the values listed in the ValueChecked or ValueUnchecked properties.
If the field with which a check box is associated is a logical field, the check box is always checked if the contents of the field is True, and it is unchecked if the contents of the field is False. In this case, strings entered in the ValueChecked and ValueUnchecked properties have no effect on logical fields.
-
11:
کد:
Editing in the grid
When a user edits a record in the grid, changes to each field are posted to an internal record buffer, but are not posted until the user moves to a different record in the grid. Even if focus is changed to another control on a form, the grid does not post changes until another the cursor for the dataset is moved to another record. When a record is posted, the dataset checks all associated data-aware components for a change in status. If there is a problem updating any fields that contain modified data, the grid raises an exception, and does not modify the record.
Note
If your application caches updates, posting record changes only adds them to an internal cache. They are not posted back to the underlying database table until your application applies the updates.
You can cancel all edits for a record by pressing Esc in any field before moving to another record.
-
12:
کد:
Navigating and manipulating records
TDBNavigator provides users a simple control for navigating through records in a dataset, and for manipulating records. The navigator consists of a series of buttons that enable a user to scroll forward or backward through records one at a time, go to the first record, go to the last record, insert a new record, update an existing record, post data changes, cancel data changes, delete a record, and refresh record display.
The following figure shows the navigator that appears by default when you place it on a form at design time. The navigator consists of a series of buttons that let a user navigate from one record to another in a dataset, and edit, delete, insert, and post records. The VisibleButtons property of the navigator enables you to hide or show a subset of these buttons dynamically. See Choosing navigator buttons to display for more information.
-
13:
کد:
Creating Internet server applications: Overview
Web server applications extend the functionality and capability of existing Web servers. A Web server application receives HTTP request messages from the Web server, performs any actions requested in those messages, and formulates responses that it passes back to the Web server. Many operations that you can perform with an ordinary application can be incorporated into a Web server application.
The IDE provides two different architectures for developing Web server applications: Web Broker and WebSnap. Although these two architectures are different, WebSnap and Web Broker have many common elements. The WebSnap architecture acts as a superset of Web Broker. It provides additional components and new features like the Preview tab, which allows the content of a page to be displayed without the developer having to run the application. Applications developed with WebSnap can include Web Broker components, whereas applications developed with Web Broker cannot include WebSnap components.
-
14:
کد:
Components and classes
Because components are classes, component writers work with objects at a different level from application developers. Creating new components requires that you derive new classes.
Briefly, there are two main differences between creating components and using them in applications. When creating components,
You access parts of the class that are inaccessible to application programmers.
You add new parts (such as properties) to your components.
Because of these differences, you need to be aware of more conventions and think about how application developers will use the components you write.
-
15:
کد:
Creating graphic controls
If your control does not need to receive input focus, you can make it a graphic control. Graphic controls are similar to windowed controls, but have no window handles, and therefore consume fewer system resources. Components like TLabel, which never receive input focus, are graphic controls. Although these controls cannot receive focus, you can design them to react to mouse messages.
You can create custom controls through the TGraphicControl component. TGraphicControl is an abstract class derived from TControl. Although you can derive controls directly from TControl, it is better to start from TGraphicControl, which provides a canvas to paint on and on Windows, handles WM_PAINT messages; all you need to do is override the Paint method.
-
16:
کد:
Why create properties?
From the application developer's standpoint, properties look like variables. Developers can set or read the values of properties as if they were fields. (About the only thing you can do with a variable that you cannot do with a property is pass it as a var parameter.)
Properties provide more power than simple fields because
Application developers can set properties at design time. Unlike methods, which are available only at runtime, properties let the developer customize components before running an application. Properties can appear in the Object Inspector, which simplifies the programmer's job; instead of handling several parameters to construct an object, the Object Inspector supplies the values. The Object Inspector also validates property assignments as soon as they are made.
Properties can hide implementation details. For example, data stored internally in an encrypted form can appear unencrypted as the value of a property; although the value is a simple number, the component may look up the value in a database or perform complex calculations to arrive at it. Properties let you attach complex effects to outwardly simple assignments; what looks like an assignment to a field can be a call to a method which implements elaborate processing.
Properties can be virtual. Hence, what looks like a single property to an application developer may be implemented differently in different components.
A simple example is the Top property of all controls. Assigning a new value to Top does not just change a stored value; it repositions and repaints the control. And the effects of setting a property need not be limited to an individual component; for example, setting the Down property of a speed button to True sets Down property of all other speed buttons in its group to False.