Deciding which runtime packages to use

Kylix ships with several precompiled runtime packages, including bplclx, which supply basic language and component support. The bplclx package contains the most commonly used components, system functions, and user interface elements. It does not include database components, which are available in separate packages. For a list of the other runtime packages shipped with Kylix, see runtime packages, precompiled in your online Help index. To create a client server database application that uses...

Changing file attributes

Every file has various attributes stored by the operating system as bitmapped flags. File attributes include such items as whether a file is read-only or a hidden file. Changing a file's attributes requires three steps reading, changing, and setting. You may be limited as to what you may modify depending on your file access rights. Reading file attributes Operating systems store file attributes in various ways, generally as bitmapped flags. To read a file's attributes, pass the file name to the...

Adding property editors

The Object Inspector provides default editing for all types of properties. You can, however, provide an alternate editor for specific properties by writing and registering property editors. You can register property editors that apply only to the properties in the components you write, but you can also create editors that apply to all properties of a certain type. At the simplest level, a property editor can operate in either or both of two ways displaying and allowing the user to edit the...

Kylix and Delphi unit comparison

All of the objects in the VCL or CLX are defined in unit files (.pas source files). For example, you can find the implementation of TObject in the System unit, and the Classes unit defines the base TComponent class. When you drop an object onto a form or use an object within your application, the name of the unit is added to the uses clause which tells the compiler which units to link into the project. This section provides tables that list the units that are in Kylix and the comparable unit in...

The structure of metadata datasets

For each type of metadata you can access using TSQLDataSet, there is a predefined set of columns (fields) that are populated with information about the items of the requested type. When you request information about tables (stTables or stSysTables), the resulting dataset includes a record for each table. It has the following columns Table 18.1 Columns in tables of metadata listing tables RECNO ftlnteger CATALOG_NAME ftString A record number that uniquely identifies each record. The name of the...

Converting field values

Conversion properties attempt to convert one data type to another. For example, the AsString property converts numeric and Boolean values to string representations. The following table lists field component conversion properties, and which properties are recommended for field components by field-component class Note that some columns in the table refer to more than one conversion property (such as AsFloat, AsCurrency, and AsBCD). This is because all field data types that support one of those...

Avoiding simultaneous access

To avoid clashing with other threads when accessing global objects or variables, you may need to block the execution of other threads until your thread code has finished an operation. Be careful not to block other execution threads unnecessarily. Doing so can cause performance to degrade seriously and negate most of the advantages of using multiple threads. Some objects have built-in locking that prevents the execution of other threads from using that object instance. For example, canvas...

Creating methods to store and load property values

To store and load unpublished properties, you must first create a method to store your property value and another to load your property value. You have two choices Create a method of type TWriterProc to store your property value and a method of type TReaderProc to load your property value. This approach lets you take advantage of Kylix's built-in capabilities for saving and loading simple types. If your property value is built out of types that Kylix knows how to save and load, use this...

Storing and loading unpublished properties

By default, only published properties are loaded and saved with a component. However, it is possible to load and save unpublished properties. This allows you to have persistent properties that do not appear in the Object Inspector. It also allows components to store and load property values that Kylix does not know how to read or write because the value of the property is too complex. For example, the TStrings object can't rely on Kylix's automatic behavior to store and load the strings it...

Determining and setting dataset states

The state or mode of a dataset determines what can be done to its data. For example, when a dataset is closed, its state is dsInactive, meaning that nothing can be done to its data. At runtime, you can examine a dataset's read-only State property to determine its current state. The following table summarizes possible values for the State property and what they mean Table 16.1 Values for the dataset State property Table 16.1 Values for the dataset State property DataSet closed. Its data is...

Filling in the cells

A grid control fills in its contents cell-by-cell. In the case of the calendar, that means calculating which date, if any, belongs in each cell. The default drawing for grid cells takes place in a virtual method called DrawCell. To fill in the contents of grid cells, override the DrawCell method. The easiest part to fill in is the heading cells in the fixed row. The runtime library contains an array with short day names, so for the calendar, use the appropriate one for each column...

Integrated development environment

When you start Kylix, you are immediately placed within the integrated development environment, also called the IDE. This environment provides all the tools you need to design, develop, test, debug, and deploy applications. Kylix's development environment includes a visual form designer, Object Inspector, Component palette, Project Manager, source code editor, and debugger. You can move freely from the visual representation of an object (in the form designer), to the Object Inspector to edit...

Displaying a single record

In many applications, you may only want to provide information about a single record of data at a time. For example, an order-entry application may display the information about a single order without indicating what other orders are currently logged. This information probably comes from a single record in an orders dataset. If you are connecting your user interface directly to a unidirectional dataset, a singlerecord user interface is the only available possibility. Applications that display a...

Creating projects

All of Kylix's application development revolves around projects. When you create an application in Kylix you are creating a project. A project is a collection of files that make up an application. Some of these files are created at design time. Others are generated automatically when you compile the project source code. You can view the contents of a project in a project management tool called the Project Manager. The Project Manager lists, in a hierarchical view, the unit names, the forms...

Using an SQL client dataset

TSQLClientDataSet is a special type of client dataset designed for simple two-tiered applications. Like a unidirectional dataset, it can use an SQL connection component to connect to a database server and specify an SQL statement to execute on that server. Like other client datasets, it buffers data in memory to allow full navigation and editing support. TSQLClientDataSet works the same way as a generic client dataset (TClientDataSet) that is linked to a unidirectional dataset by a dataset...

Responding to client update requests

A provider applies updates to database records based on a Delta data packet received from a client dataset. The client dataset requests updates by calling the ApplyUpdates method (indirectly, through the IAppServer interface). As with all method calls that are made through the IAppServer interface, the provider has an opportunity to communicate persistent state information with the client dataset before and after the call to ApplyUpdates. This communication takes place using the...

Using maintained aggregates

Client datasets provide support for summarizing data over groups of records. Because these summaries are automatically updated as you edit the data in the dataset, this summarized data is called a maintained aggregate. In their simplest form, maintained aggregates let you obtain information such as the sum of all values in a column of the client dataset. They are flexible enough, however, to support a variety of summary calculations and to provide subtotals over groups of records defined by a...

Generating the content of response messages

Kylix provides a number of objects to assist your action items in producing content for HTTP response messages. You can use these objects to generate strings of HTML commands that are saved in a file or sent directly back to the Web client. You can write your own content producers, deriving them from TCustomContentProducer or one of its descendants. TCustomContentProducer provides a generic interface for creating any MIME type as the content of an HTTP response message. Its descendants include...

Navigating data in client datasets

If an application uses standard data-aware controls, then a user can navigate through a client dataset's records using the built-in behavior of those controls. You can also navigate programmatically through records using standard dataset methods such as First, Last, Next, and Prior. For more information about these methods, see Navigating datasets on page 16-8. Also inherited from TDataSet are the Locate and Lookup methods, which search for a particular record based on the values of specified...

Creating HTTP response messages

When the Web server application creates a TWebRequest object for an incoming HTTP request message, it also creates a corresponding TWebResponse object to represent the response message that will be sent in return. In Apache DSO applications, the response message is encapsulated by a TApacheResponse object. Console CGI applications use TCGIResponse objects. The action items that generate the response to a Web client request fill in the properties of the response object. In some cases, this may...

Representing the results of a stored procedure

Stored procedures are sets of SQL statements that are named and stored on an SQL server. They typically handle frequently-repeated database-related tasks. They are especially useful for operations that act upon large numbers of rows in database tables or that use aggregate or mathematical functions. Using stored procedures typically improves the performance of a database application by Taking advantage of the server's usually greater processing power and speed. Reducing network traffic by...

Accessing field values with a datasets FieldByName method

You can also access the value of a field with a dataset's FieldByName method. This method is useful when you know the name of the field you want to access, but do not have access to the underlying table at design time. To use FieldByName, you must know the dataset and name of the field you want to access. You pass the field's name as an argument to the method. To access or change the field's value, convert the result with the appropriate field component conversion property, such as AsString or...

Using socket components

The Internet palette page includes socket components client sockets and server sockets that allow your network application to form connections to other machines, and that allow you to read and write information over that connection. Associated with each of these socket components are socket objects, which represent the endpoint of an actual socket connection. The socket components use the socket objects to encapsulate the operating system API calls, so that your application does not need to be...

Responding to socket events

When writing applications that use sockets, you can write or read to the socket anywhere in the program. You can write to the socket using the SendBufmethod in your program after the socket has been opened. The OnSend and RecvBuf events are triggered every time something is written or read from the socket. They can be used for filtering. Every time you read or write, a read or write event is triggered. Both client sockets and server sockets generate error events when they receive error messages...

Working with reference fields

Reference fields store a pointer or reference to another ADT object. This ADT object is a single record of another object table. Reference fields always refer to a single record in a dataset object table . The data in the referenced object is returned in a nested dataset, but can also be accessed via the Fields property on the TReferenceField. In a TDBGrid control a reference field is designated in each cell of the dataset column, with Reference and, at runtime, an ellipsis button to the right....

Property categories

In the IDE, the Object Inspector lets you selectively hide and display properties based on property categories. The properties of new custom components can be fit into this scheme by registering properties in categories. Do this at the same time you register the component by calling RegisterPropertyInCategory or RegisterPropertiesInCategory. Use RegisterPropertyInCategory to register a single property. Use RegisterPropertiesInCategory to register multiple properties in a single function call....

Using a client dataset with data stored on disk

The simplest form of database application you can write does not use a database server at all. Instead, it uses the ability of client datasets to save themselves to a file and to load the data from a file. The architecture for this type of application is illustrated in Figure 14.2 Figure 14.2 Architecture of a file-based database application This simple file-based architecture is a single-tiered application. The logic that manipulates database information is in the same application that...

The Web dispatcher

If you are using a Web module, it acts as a Web dispatcher. If you are using a preexisting data module, you must add a single dispatcher component TWebDispatcher to that data module. The dispatcher maintains a collection of action items that know how to handle certain kinds of request messages. When the Web application passes a request object and a response object to the dispatcher, it chooses one or more action items to respond to the request. Open the action editor from the Object Inspector...

Setting up masterdetail relationships

There are two ways to set up a master detail relationship that uses a unidirectional dataset as the detail set. Which method you use depends on the type of unidirectional dataset you are using. Once you have set up such a relationship, the unidirectional dataset the many in a one-to-many relationship provides access only to those records that correspond to the current record on the master set the one in the one-to-many relationship . Setting up master detail relationships with TSQLDataSet or...