Character types

Delphi has three character types Char, AnsiChar, and WideChar. The Char character type came from standard Pascal, and was used in Turbo Pascal and then in Object Pascal. Later Object Pascal added AnsiChar and WideChar as specific character types that were used to support standards for character representation on the Windows operating system. AnsiChar was introduced to support an 8-bit character ANSI standard, and WideChar was introduced to support a 16-bit Unicode standard. The name WideChar is...

CoClasses and class factories

A COM object is an instance of a CoClass, which is a class that implements one or more COM interfaces. The COM object provides the services as defined by its interfaces. CoClasses are instantiated by a special type of object called a class factory. Whenever an object's services are requested by a client, a class factory creates an object instance for that particular client. Typically, if another client requests the object's services, the class factory creates another object instance to service...

Executing queries that dont return a result set

When a query returns a set of records (such as a SELECT query), you execute the query the same way you populate any dataset with records by setting Active to True or calling the Open method. However, often SQL commands do not return any records. Such commands include statements that use Data Definition Language (DDL) or Data Manipulation Language (DML) statements other than SELECT statements (For example, INSERT, DELETE, UPDATE, CREATE INDEX, and ALTER TABLE commands do not return any records)....

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...

Specifying property categories

When you register properties in a category, you can use any string you want as the name of the category. If you use a string that has not been used before, the Object Inspector generates a new property category class with that name. You can also, however, register properties into one of the categories that are built-in. The built-in property categories are described in Table 47.4. Action Properties related to runtime actions the Enabled and Hint properties of Database Properties related to...

Using unidirectional datasets

DbExpress is a set of lightweight database drivers that provide fast access to SQL database servers. For each supported database, dbExpress provides a driver that adapts the server-specific software to a set of uniform dbExpress interfaces. When you deploy a database application that uses dbExpress, you need only include a dll (the server-specific driver) with the application files you build. dbExpress lets you access databases using unidirectional datasets. Unidirectional datasets are designed...

Displaying converting and accessing field values

Data-aware controls such as TDBEdit and TDBGrid automatically display the values associated with field components. If editing is enabled for the dataset and the controls, 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 to connect to datasets, display values, and make updates without requiring extra programming on your part. Use them whenever possible in your database applications. For...

Status bars

Although you can use a panel to make a status bar, it is simpler to use the status bar component. By default, the status bar's Align property is set to alBottom, which takes care of both position and size. If you only want to display one text string at a time in the status bar, set its SimplePanel property to True and use the SimpleText property to control the text displayed in the status bar. You can also divide a status bar into several text areas, called panels. To create panels, edit the...

Passing object references

Note Information on passing object references applies only to MTS, not COM+. This mechanism is needed under MTS because it is necessary to ensure that all pointers to objects running under MTS are routed through interceptors. Because interceptors are built into COM+, you do not need to pass object references. Under MTS, you can pass object references, (for example, for use as a callback) only in the following ways Through return from an object creation interface, such as CoCreateInstance (or...

Adding properties and methods to an interface or dispinterface

To add properties or methods to an interface or dispinterface, 1 Select the interface, and choose either a property or method icon from the toolbar. If you are adding a property, you can click directly on the property icon to create a read write property (with both a getter and a setter), or click the down arrow to display a menu of property types. The property access method members or method member is added to the object list pane, prompting you to add a name. The new member contains default...

Using file streams

TFileStream is a class that enables applications to read from and write to a file on disk. It is used for high-level object representations of file streams. TFileStream offers multiple functionality persistence, interaction with other streams, and file I O. TFileStream is a descendant of the stream classes. As such, one advantage of using file streams is that they inherit the ability to persistently store component properties. The stream classes work with the TFiler classes, TReader, and...

Building a Web Service server

Use the following steps to build a server application that implements a Web Service 1 Define the interfaces that make up your Web Service. These interface definitions must be invokable interfaces. It is a good idea to create your interface definitions in their own units, separate from the unit that contains the implementation classes. In this way, the unit that defines the interfaces can be included in both the server and client applications. In the initialization section of this unit, add code...

Using the Borland Database Engine

The Borland Database Engine (BDE) is a data-access mechanism that can be shared by several applications. The BDE defines a powerful library of API calls that can create, restructure, fetch data from, update, and otherwise manipulate local and remote database servers. The BDE provides a uniform interface to access a wide variety of database servers, using drivers to connect to different databases. Depending on your version of Delphi, you can use the drivers for local databases (Paradox, dBASE,...

Using the ADT fields Field Values property

You can access the value of a child field with the TADTField's FieldValues property. FieldValues accepts and returns a Variant, so it can handle and convert fields of any type. The index parameter is an integer value that specifies the offset of the field. CityEdit.Text Because FieldValues is the default property of TADTField, the property name (FieldValues) can be omitted. Thus, the following statement is equivalent to the one above CityEdit.Text

Displaying ADT and array fields

Both ADT and array fields contain child fields that can be displayed through data-aware controls. Data-aware controls such as TDBEdit that represent a single field value display child field values in an uneditable comma delimited string. In addition, if you set the control's DataField property to the child field instead of the object field itself, the child field can be viewed an edited just like any other normal data field. A TDBGrid control displays ADT and array field data differently,...

Allowing toggle buttons

Sometimes you want to be able to click a button in a group that's already pressed and have it pop up, leaving no button in the group pressed. Such a button is called a toggle. Use AllowAllUp to create a grouped button that acts as a toggle click it once, it's down click it again, it pops up. To make a grouped speed button a toggle, set its AllowAllUp property to True. Setting AllowAllUp to True for any speed button in a group automatically sets the same property value for all buttons in the...

Producer template

HTML templates typically contain some static HTML mixed in with transparent tags or server-side script. When page producers create their content, they replace the transparent tags with appropriate values and execute the server-side script to produce the HTML that is displayed by a client browser. The XSLPageProducer is an exception to this. It uses XSL templates, which contain XSL rather than HTML. The XSL templates do not support transparent tags or...

Working with a nodes value

Given an IXMLNode interface, you can check whether it represents an internal node or a leaf node by checking the IsTextElement property. If it represents a leaf node, you can read or set its value using the Text property. If it represents an internal node, you can access its child nodes using the ChildNodes property. Thus, for example, using the XML document above, you can read the price of Inprise's stock as follows InpriseStock Price

Loading and storing graphics

All pictures and graphics in Delphi can load their images from files and store them back again (or into different files). You can load or store the image of a picture at any time. CLX Note You can also load images from and save them to a Qt MIME source, or a stream object if creating CLX components. To load an image into a picture from a file, call the picture's LoadFromFile method. To save an image from a picture into a file, call the picture's SaveToFile method. LoadFromFile and SaveToFile...

Starting a transaction

When you start a transaction, all subsequent statements that read from or write to the database occur in the context of that transaction, until the transaction is explicitly terminated or (in the case of overlapping transactions) until another transaction is started. Each statement is considered part of a group. Changes must be successfully committed to the database, or every change made in the group must be undone. While the transaction is in process, your view of the data in database tables...

Applying cached updates using a database

To apply cached updates to one or more datasets in the context of a database connection, call the database component's ApplyUpdates method. The following code applies updates to the CustomersQuery dataset in response to a button click event procedure TForm1.ApplyButtonClick(Sender TObject) begin for local databases such as Paradox, dBASE, and FoxPro set Translsolation to DirtyRead if not (Databasel.IsSQLBased) and not (Databasel.Translsolation tiDirtyRead) then Databasel.Translsolation...

Adding component editors

Component editors determine what happens when the component is double-clicked in the designer and add commands to the context menu that appears when the component is right-clicked. They can also copy your component to the Windows clipboard in custom formats. If you do not give your components a component editor, Delphi uses the default component editor. The default component editor is implemented by the class TDefaultEditor. TDefaultEditor does not add any new items to a component's context...

Waiting for a task to be completed

Sometimes, you need to wait for a thread to finish some operation rather than waiting for a particular thread to complete execution. To do this, use an event object. Event objects (TEvent) should be created with global scope so that they can act like signals that are visible to all threads. When a thread completes an operation that other threads depend on, it calls TEvent.SetEvent. SetEvent turns on the signal, so any other thread that checks will know that the operation has completed. To turn...

Working with XML nodes

Once an XML document has been parsed by a DOM implementation, the data it represents is available as a hierarchy of nodes. Each node corresponds to a tagged element in the document. For example, given the following XML Component palette< xml version 1.0 standalone 'yes' > < DOCTYPE stockholdings SYSTEM sth.dtd> < StockList> < name> Inprise (Borland)< name> < price> 15.375< price> < symbol> INPR< symbol> < shares> 100< shares> < Stock> < Stock...

Directory structure on Linux

Any file or device can be mounted anywhere on the file system. Note Linux pathnames use forward slashes as opposed to Windows use of backslashes. The initial slash stands for the root directory. Following are some commonly used directories in Linux. Table 10.8 Common Linux directories The root or top directory of the entire Linux file system root The root file system the Superuser's home directory home username Files owned by the user where username is the...

Overview of ActiveX control creation

Creating ActiveX controls using Delphi is very similar to creating ordinary controls or forms. This differs markedly from creating other COM objects, where you first define the object's interface and then complete the implementation. To create ActiveX controls (other than Active Forms), you reverse this process, starting with the implementation of a VCL control, and then generating the interface and type library once the control is written. When creating Active Forms, the interface and type...

Using TSQLMonitor to monitor SQL commands

TSQLConnection uses a companion component, TSQLMonitor, to intercept these messages and save them in a string list. TSQLMonitor works much like the SQL monitor utility that you can use with the BDE, except that it monitors only those commands involving a single TSQLConnection component rather than all commands managed by dbExpress. 1 Add a TSQLMonitor component to the form or data module containing the TSQLConnection component whose SQL commands you want to monitor. 2 Set its SQLConnection...

Limiting records with ranges

You can temporarily view and edit a subset of data for any dataset by using filters (see Displaying and editing a subset of data using filters on page 18-12). Some table-type datasets support an additional way to access a subset of available records, called ranges. Ranges only apply to TTable and to client datasets. Despite their similarities, ranges and filters have different uses. The following topics discuss the differences between ranges and filters and how to use ranges. Understanding the...

Defining a COM objects interface

When you use a wizard to create a COM object, the wizard automatically generates a type library (unless you specify otherwise in the COM object wizard). The type library provides a way for host applications to find out what the object can do. It also lets you define your object's interface using the Type Library editor. The interfaces you define in the Type Library editor define what properties, methods, and events your object exposes to clients. Note If you selected an existing interface in...

Writing portable code

If you are writing cross-platform applications that are meant to run on Windows and Linux, you can write code that compiles under different conditions. Using conditional compilation, you can maintain your Windows coding, yet also make allowances for Linux operating system differences. To create applications that are easily portable between Windows and Linux, remember to reduce or isolate calls to platform-specific (Win32 or Linux) APIs use CLX methods instead. eliminate Windows messaging...

Calling invokable interfaces

To call an invokable interface, your client application must include any units that define the invokable interfaces and any remotable classes that implement complex types. If the server is written in Delphi, these should be the same units that the server application uses to define and register these interfaces and classes. It is best to use the same unit, because when you register an invokable interface or remotable class, it is given a uniform resource identifier (URI) that uniquely identifies...

Implementing COM objects with wizards

Delphi makes it easier to write COM server applications by providing wizards that handle many of the details involved. Delphi provides separate wizards to create the following An Active Server Object (for embedding in an Active Server page) The wizards handle many of the tasks involved in creating each type of COM object. They provide the required COM interfaces for each type of object. As shown in Figure 33.6, with a simple COM object, the wizard implements the one required COM interface,...

Generating WSDL documents for a Web Service application

If you include the same units that define and register your invokable interfaces, the classes that represent complex type information, and your remotable exceptions in a Delphi client application, it can generate calls to use your Web Service. All you need to do is supply the URL where you install your Web Service application. However, you may want to make your Web Service available to a wider range of clients. For example, you may have clients that are not written in Delphi. If you are...

HTTP server activity

The client server nature of Web browsers is deceptively simple. To most users, retrieving information on the World Wide Web is a simple procedure click on a link, and the information appears on the screen. More knowledgeable users have some understanding of the nature of HTML syntax and the client server nature of the protocols used. This is usually sufficient for the production of simple, page-oriented Web site content. Authors of more complex Web pages have a wide variety of options to...

Creating masterdetail relationships

Table-type datasets can be linked into master detail relationships. When you set up a master detail relationship, you link two datasets so that all the records of one (the detail) always correspond to the single current record in the other (the master). Table-type datasets support master detail relationships in two very distinct ways All table-type datasets can act as the detail of another dataset by linking cursors. This process is described in Making the table a detail of another dataset...

Environmental differences between Windows and Linux

Currently, cross-platform means an application that can run virtually unchanged on both the Windows and Linux operating systems. The following table lists some of the differences between Linux and the Windows operating environments. Table 10.7 Differences in the Linux and Windows operating environments File name case sensitivity Line ending characters In Linux, a capital letter is not the same as a lowercase letter. The file Test.txt is not the same file as test.txt. You need to pay close...

Using default formatting for numeric date and time fields

Delphi provides built-in display and edit format routines and intelligent default formatting for TFloatField, TCurrencyField, TBCDField, TFMTBCDField, TIntegerField, TSmallIntField, TWordField, TDateField, TDateTimeField, and TTimeField, and TSQLTimeStampField components. To use these routines, you need do nothing. Persistent field components Default formatting is performed by the following routines Table 19.4 Field component formatting routines FormatFloat TFloatField, TCurrencyField...

Implementing interfaces across the hierarchy

Using interfaces offers a design approach to separating the way a class is used from the way it is implemented. Two classes can implement the same interface without requiring that they descend from the same base class. This polymorphic invocation of the same methods on unrelated objects is possible as long as the objects implement the same interface. For example, consider the interface, IPaint interface procedure Paint-end TSquare class(TPolygonObject, IPaint) TCircle class(TCustomShape,...

Designing database applications

Using databases 14-1 Types of databases 14-2 Database security 14-3 Referential integrity, stored procedures, and triggers 14-5 Database architecture 14-5 General structure 14-6 The user interface form 14-6 Using a dedicated file on disk 14-9 Connecting to another dataset 14-10 Connecting a client dataset to another dataset in the same application 14-11 Using a multi-tiered architecture. . . . 14-12 Combining approaches 14-14 Designing the user interface 14-15 Analyzing data 14-15 Writing...

Creating Internet applications

About Web Broker and WebSnap 27-1 Terminology and standards 27-2 Parts of a Uniform Resource Locator 27-3 HTTP request header information 27-4 HTTP server activity 27-4 Composing client requests 27-4 Serving client requests 27-5 Responding to client requests 27-5 Types of Web server applications 27-6 Debugging server applications 27-7 Using the Web Application Debugger . . . . 27-7 Launching your application with the Web Application Debugger 27-7 Converting your application to another type of...

Integrated development environment

When you start Delphi, 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. Delphi's development environment includes a visual form designer, Object Inspector, Object TreeView, Component palette, Project Manager, source code editor, and debugger among other tools. Some tools may not be included in all versions of the product. You can move freely...

Creating projects

All of Delphi's application development revolves around projects. When you create an application in Delphi 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...

Creating SQL statements for update components

To update a record in an associated dataset, an update object uses one of three SQL statements. Each update object can only update a single table, so the object's update statements must each reference the same base table. The three SQL statements delete, insert, and modify records cached for update. You must provide these statements as update object's DeleteSQL, InsertSQL, and ModifySQL properties. You can provide these values at design time or at runtime. For example, the following code...

Retrieving information about a session

You can retrieve information about a session and its database components by using a session's informational methods. For example, one method retrieves the names of all aliases known to the session, and another method retrieves the names of tables associated with a specific database component used by the session. Table 20.4 summarizes the informational methods to a session component Table 20.4 Database-related informational methods for session components GetDriverNames GetDriverParams...

Working with multimedia

Delphi allows you to add multimedia components to your applications. To do this, you can use either the TAnimate component on the Win32 page or the TMediaPlayer component on the System page of the Component palette. Use the animate component when you want to add silent video clips to your application. Use the media player component when you want to add audio and or video clips to an application. For more information on the TAnimate and TMediaPlayer components, see the VCL on-line help. The...

Creating a property page for an ActiveX control

A property page is a dialog box similar to the Delphi Object Inspector in which users can change the properties of an ActiveX control. A property page dialog allows you to group many properties for a control together to be edited at once. Or, you can provide a dialog box for more complex properties. Typically, users access the property page by right-clicking the ActiveX control and choosing Properties. The process of creating a property page is similar to creating a form, you 2 Add controls to...

Setting up a transaction object on the client side

A client-based application can control transaction context through the ITransactionContextEx interface. The following code example shows how a client application uses CreateTransactionContextEx to create the transaction context. This method returns an interface to this object. This example wraps the call to the transaction context in a call to OleCheck which is necessary because the methods of IObjectContext are exposed by Windows directly and are therefore not declared as safecall. procedure...

Customizing the ActiveX controls interface

The ActiveX Control and ActiveForm wizards generate a default interface for the ActiveX wrapper class. This default interface simply exposes the properties, methods, and events of the original VCL control or form, with the following exceptions Data-aware properties do not appear. Because ActiveX controls have a different mechanism for making controls data-aware than VCL controls, the wizards do not convert properties related to data. See Enabling simple data binding with the type library on...

Managing database connections

You can use a session component to manage the database connections within it. The session component includes properties and methods you can use to Close database connections. Close and free all inactive temporary database connections. Locate specific database connections. Iterate through all open database connections. To open a database connection within a session, call the OpenDatabase method. OpenDatabase takes one parameter, the name of the database to open. This name is a bDe alias or the...

Writing Webbased client applications

If you want to create Web-based clients for your multi-tiered database application, you must replace the client tier with a special Web application that acts simultaneously as a client to an application server and as a Web server application that is installed with a Web server on the same machine. This architecture is illustrated in Figure 25.1. Figure 25.1 Web-based multi-tiered database application Figure 25.1 Web-based multi-tiered database application There are two approaches that you can...

Deploying database applications

Applications that access databases involve special installation considerations beyond copying the application's executable file onto the host computer. Database access is most often handled by a separate database engine, the files of which cannot be linked into the application's executable file. The data files, when not created beforehand, must be made available to the application. Multi-tier database applications require even more specialized handling on installation, because the files that...

Using Indexes to search for records

You can search against any dataset using the Locate and Lookup methods of TDataSet. However, by explicitly using indexes, some table-type datasets can improve over the searching performance provided by the Locate and Lookup methods. ADO datasets all support the Seek method, which moves to a record based on a set of field values for fields in the current index. Seek lets you specify where to move the cursor relative to the first or last matching record. TTable and all types of client dataset...

Accessing data in a reference field

You can access the data in a reference field in the same way you access a nested dataset 1 Create a persistent TDataSetField object by invoking the Fields editor for the parent dataset. 2 Create a dataset to represent the value of that dataset field. 3 Set that DataSetField property of the dataset created in step 2 to the persistent dataset field you created in step 1. If the reference is assigned, the reference dataset will contain a single record with the referenced data. If the reference is...

Associating a data control with a dataset

Data controls connect to datasets by using a data source. A data source component (TDataSource) acts as a conduit between the control and a dataset containing data. Each data-aware control must be associated with a data source component to have data to display and manipulate. Similarly, all datasets must be associated with a data source component in order for their data to be displayed and manipulated in data-aware controls on a form. Note Data source components are also required for linking...

Overview of component creation

VCL and CLX 40-1 Components and classes 40-2 How do you create components 40-2 Modifying existing controls 40-3 Creating windowed controls 40-3 Creating graphic controls 40-4 Subclassing Windows controls 40-4 Creating nonvisual components 40-5 What goes into a component 40-5 Removing dependencies 40-5 Properties, methods, and events 40-6 Graphics encapsulation 40-7 Registration 40-8 Creating a new component 40-8 Using the Component wizard 40-9 Creating a component manually 40-11 Creating a unit...

Hiding implementation details

Declaring part of a class as private makes that part invisible to code outside the class's unit file. Within the unit that contains the declaration, code can access the part as if it were public. Here is an example that shows how declaring a field as private hides it from application developers. The listing shows two VCL form units. Each form has a handler for its OnCreate event which assigns a value to a private field. The compiler allows assignment to the field only in the form where it is...

Using object fields

Object fields are fields that represent a composite of other, simpler data types. These include ADT (Abstract Data Type) fields, Array fields, DataSet fields, and Reference fields. All of these field types either contain or reference child fields or other data sets. ADT fields and array fields are fields that contain child fields. The child fields of an ADT field can be any scalar or object type (that is, any other field type). These child fields may differ in type from each other. An array...

Using nested detail tables

A nested table is a detail dataset that is the value of a single dataset field in another (master) dataset. For datasets that represent server data, a nested detail dataset can only be used for a dataset field on the server. TClientDataSet components do not represent server data, but they can also contain dataset fields if you create a dataset for them that contains nested details, or if they receive data from a provider that is linked to the master table of a master detail relationship. Note...

Working with frames

A frame (TFrame), like a form, is a container for other components. It uses the same ownership mechanism as forms for automatic instantiation and destruction of the components on it, and the same parent-child relationships for synchronization of component properties. In some ways, however, a frame is more like a customized component than a form. Frames can be saved on the component palette for easy reuse, and they can be nested within forms, other frames, or other container objects. After a...

Working with BDE aliases

Each database component associated with a session has a BDE alias (although optionally a fully-qualified path name may be substituted for an alias when accessing Paradox and dBASE tables). A session can create, modify, and delete aliases during its lifetime. The AddAlias method creates a new BDE alias for an SQL database server. AddAlias takes three parameters a string containing a name for the alias, a string that specifies the SQL Links driver to use, and a string list populated with...

Drawing ownerdraw items

When an application needs to draw or redraw an owner-draw control, the operating system generates draw-item events for each visible item in the control. Depending on the control, the item may also receive draw events for the item as a whole or subitems. To draw each item in an owner-draw control, attach an event handler to the draw-item event for that control. The names of events for owner drawing typically start with one of the following OnDraw, such as OnDrawItem or OnDrawCell OnCustomDraw,...

TInterfaced Object

Delphi defines a simple class, TInterfacedObject, that serves as a convenient base because it implements the methods of IInterface. TInterfacedObject class is declared in the System unit as follows TInterfacedObject class (TObject, IInterface) protected function QueryInterface(const IID TGUID out Obj) HResult stdcall function _AddRef Integer stdcall function _Release Integer stdcall public procedure AfterConstruction override procedure BeforeDestruction override class function NewInstance...

Renaming a file

To change a filename, simply use the RenameFile function function RenameFile(const OldFileName, NewFileName string) Boolean which changes a filename, identified by OldFileName, to the name specified by NewFileName. If the operation succeeds, RenameFile returns True. If it cannot rename the file, for example, if a file called NewFileName already exists, it returns False. For example if not RenameFile('OLDNAME.TXT','NEWNAME.TXT') then ErrorMsg('Error renaming file ') You cannot rename (move) a...

Handling the OnPopup event

You may want to adjust pop-up menu items before displaying the menu, just as you may want to enable or disable items on a regular menu. With a regular menu, you can handle the OnClick event for the item at the top of the menu, as described in Disabling menu items on page 7-10. With a pop-up menu, however, there is no top-level menu bar, so to prepare the popup menu commands, you handle the event in the menu component itself. The pop-up menu component provides an event just for this purpose,...

Creating an ActiveX control

An ActiveX control is a software component that integrates into and extends the functionality of any host application that supports ActiveX controls, such as C++Builder, Delphi, Visual Basic, Internet Explorer, and (given a plug-in) Netscape Navigator. ActiveX controls implement a particular set of interfaces that allow this integration. For example, Delphi comes with several ActiveX controls, including charting, spreadsheet, and graphics controls. You can add these controls to the component...

Deploying CLX applications

If you are writing cross-platform applications that will be deployed on both Windows and Linux, you need to compile and deploy the applications on both platforms. The steps for deploying CLX applications are the same as those for general applications. For information on deploying general applications, see Deploying general applications on page 13-1. For information on installing database CLX applications, see Deploying database applications on page 13-6. Note When deploying CLX applications on...

Adding a new index

There are three ways to add indexes to a client dataset To create a temporary index at runtime that sorts the records in the client dataset, you can use the IndexFieldNames property. Specify field names, separated by semicolons. Ordering of field names in the list determines their order in the index. This is the least powerful method of adding indexes. You can't specify a descending or case-insensitive index, and the resulting indexes do not support grouping. These indexes do not persist when...

Creating persistent fields

Persistent field components created with the Fields editor provide efficient, readable, and type-safe programmatic access to underlying data. Using persistent field components guarantees that each time your application runs, it always uses and displays the same columns, in the same order even if the physical structure of the underlying database has changed. Data-aware components and program code that rely on specific fields always work as expected. If a column on which a persistent field...

Defining new persistent fields

Besides making existing dataset fields into persistent fields, you can also create special persistent fields as additions to or replacements of the other persistent fields in a dataset. New persistent fields that you create are only for display purposes. The data they contain at runtime are not retained either because they already exist elsewhere in the database, or because they are temporary. The physical structure of the data underlying the dataset is not changed in any way. To create a new...

Adding actions to the dispatcher

Open the action editor from the Object Inspector by clicking the ellipsis on the Actions property of the dispatcher. Action items can be added to the dispatcher by clicking the Add button in the action editor. Add actions to the dispatcher to respond to different request methods or target URIs. You can set up your action items in a variety of ways. You can start with action items that preprocess requests, and end with a default action that checks whether the response is complete and either...

Disconnecting from a database server

There are two ways to disconnect a server using a connection component Set the Connected property to False. Call the Close method. Calling Close sets Connected to False. When Connected is set to False, the connection component generates a BeforeDisconnect event, where you can perform any cleanup before the connection closes. For example, you can use this event to cache information about all open datasets before they are closed. After the BeforeConnect event, the connection component closes all...

Creating multitiered applications

This chapter describes how to create a multi-tiered, client server database application. A multi-tiered client server application is partitioned into logical units, called tiers, which run in conjunction on separate machines. Multi-tiered applications share data and communicate with one another over a local-area network or even over the Internet. They provide many benefits, such as centralized business logic and thin client applications. In its simplest form, sometimes called the three-tiered...

Programming a calculated field

After you define a calculated field, you must write code to calculate its value. Otherwise, it always has a null value. Code for a calculated field is placed in the OnCalcFields event for its dataset. To program a value for a calculated field 1 Select the dataset component from the Object Inspector drop-down list. 2 Choose the Object Inspector Events page. 3 Double-click the OnCalcFields property to bring up or create a CalcFields procedure for the dataset component. 4 Write the code that sets...

Enabling Help in applications

Both the VCL and CLX support displaying Help from applications using an object-based mechanism that allows Help requests to be passed on to one of multiple external Help viewers. To support this, an application must include a class that implements the ICustomHelpViewer interface and, optionally, one of several interfaces descended from it , and registers itself with the global Help Manager. The VCL provides to all applications an instance of TWinHelpViewer, which implements all of these...

Creating resource DLLs

Isolating resources simplifies the translation process. The next level of resource separation is the creation of a resource DLL. A resource DLL contains all the resources and only the resources for a program. Resource DLLs allow you to create a program that supports many translations simply by swapping the resource DLL. Use the Resource DLL wizard to create a resource DLL for your program. The Resource DLL wizard requires an open, saved, compiled project. It will create an RC file that contains...

What CLX does differently

All of the variant safe array code that was in System is in two new units The operating system dependent code is now isolated in VarUtils.pas, and it also contains generic versions of everything needed by Variants.pas. If you are converting a VCL application that included Windows calls to a CLX application, you need to replace these calls to calls into VarUtils.pas. If you want to use variants, you must include the Variants unit to your uses clause. VarIsEmpty does a simple test against...

Loading and saving custom variant values

By default, when the custom variant is assigned as the value of a published property, it is typecast to a string when that property is saved to a form file, and converted back from a string when the property is read from a form file. You can, however, provide your own mechanism for loading and saving custom variant values in a more natural representation. To do so, the TCustomVariantType descendant must implement the IVarStreamable interface from Classes.pas. IVarStreamable defines two methods,...

Customizing decision graphs

The decision graph component, TDecisionGraph, displays fields from the decision source TDecisionSource as a dynamic graph that changes when data dimensions are opened, closed, dragged and dropped, or rearranged with the decision pivot TDecisionPivot . You can change the type, colors, marker types for line graphs, and many other properties of decision graphs. 1 Right-click it and choose Edit Chart. The Chart Editing dialog box appears. 2 Use the Chart page of the Chart Editing dialog box to view...

Controlling readwrite access to local tables

Like any table-type dataset, TTable lets you control read and write access by your application using the ReadOnly property. In addition, for Paradox, dBASE, and FoxPro tables, TTable can let you control read and write access to tables by other applications. The Exclusive property controls whether your application gains sole read write access to a Paradox, dBASE, or FoxPro table. To gain sole read write access for these table types, set the table component's Exclusive property to True before...

Adding new records

A dataset must be in dsInsert mode before an application can add new records. In code, you can use the Insert or Append methods to put a dataset into dsInsert mode if the read-only CanModify property for the dataset is True. When a dataset transitions to dsInsert mode, it first receives a BeforeInsert event. After the transition to insert mode is successfully completed, the dataset receives first an OnNewRecord event hand then an AfterInsert event. You can use these events, for example, to...

Porting your application

If you are porting an application that you want to run on both Windows and Linux, you need to modify your code or use IFDEFs to indicate sections of the code that apply specifically to Windows or Linux. Follow these general steps to port your VCL application to CLX 1 Open the project containing the application you want to change in Delphi. 2 Copy .dfm files to .xfm files of the same name for example, rename unitl.dfm to unitl.xfm . Rename or IFDEF the reference to the .dfm file in the unit file...

Animation control VCL only

The animation component is a window that silently displays an Audio Video Interleaved AVI clip. An AVI clip is a series of bitmap frames, like a movie. Although AVI clips can have sound, animation controls work only with silent AVI clips. The files you use must be either uncompressed AVI files or AVI clips compressed using run-length encoding RLE . Animation control cannot be used in cross-platform programming. Following are some of the properties of an animation component ResHandle is the...

Using Object Pascal or IDL syntax

The Text page of the Type Library editor displays your type information in one of two ways Using an extension of Object Pascal syntax. Note When working on a CORBA object, you use neither of these on the text page. Instead, you must use the CORBA IDL. You can select which language you want to use by changing the setting in the Environment Options dialog. Choose Tools Environment Options, and specify either Pascal or IDL as the Language on the Type Library page of the dialog. Note The choice of...

Specifying aggregates

To specify that you want to calculate summaries over the records in a client dataset, use the Aggregates property. Aggregates is a collection of aggregate specifications TAggregate . You can add aggregate specifications to your client dataset using the Collection Editor at design time, or using the Add method of Aggregates at runtime. If you want to create field components for the aggregates, create persistent fields for the aggregated values in the Fields Editor. Note When you create...

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 Delphi 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 Delphi's automatic behavior to store and load the strings it...

Displaying and editing a subset of data using filters

An application is frequently interested in only a subset of records from a dataset. For example, you may be interested in retrieving or viewing only those records for companies based in California in your customer database, or you may want to find a record that contains a particular set of field values. In each case, you can use filters to restrict an application's access to a subset of all records in the dataset. With unidirectional datasets, you can only limit the records in the dataset by...

Finding a file

There are three routines used for finding a file FindFirst, FindNext, and FindClose. FindFirst searches for the first instance of a filename with a given set of attributes in a specified directory. FindNext returns the next entry matching the name and attributes specified in a previous call to FindFirst. FindClose releases memory allocated by FindFirst. You should always use FindClose to terminates a FindFirst FindNext sequence. If you want to know if a file exists, a FileExists function...

Responding to mousedown messages

A MouseDown method is a protected method for a control's OnMouseDown event. The control itself calls MouseDown in response to a Windows mouse-down message. When you override the inherited MouseDown method, you can include code that provides other responses in addition to calling the OnMouseDown event. To override MouseDown, add the MouseDown method to the TDBCalendar class TDBCalendar class TSampleCalendar protected procedure MouseDown Button TButton, Shift TShiftState, X Integer, Y Integer...

Using component properties and events in a data module

Placing components in a data module centralizes their behavior for your entire application. For example, you can use the properties of dataset components, such as TClientDataSet, to control the data available to the data source components that use those datasets. Setting the ReadOnly property to True for a dataset prevents users from editing the data they see in a data-aware visual control on a form. You can also invoke the Fields editor for a dataset, by double-clicking on ClientDataSetl, to...

Events when establishing a connection

In addition to the BeforeConnect and AfterConnect events that are common to all database connection components, TADOConnection also generates an OnWillConnect and OnConnectComplete event when establishing a connection. These events occur after the BeforeConnect event. OnWillConnect occurs before the ADO provider establishes a connection. It lets you make last minute changes to the connection string, provide a user name and password if you are handling your own login support, force an...

Incremental fetching

By changing the PacketRecords property, you can specify that the client dataset fetches data in smaller chunks. PacketRecords specifies either how many records to fetch at a time, or the type of records to return. By default, PacketRecords is set to -1, which means that all available records are fetched at once, either when the client dataset is first opened, or when the application explicitly calls GetNextPacket. When PacketRecords is -1, then after the client dataset first fetches data, it...

Deploying an ActiveX control on the

Before the ActiveX controls that you create can be used by Web clients, they must be deployed on your Web server. Every time you make a change to the ActiveX control, you must recompile and redeploy it so that client applications can see the changes. Before you can deploy your ActiveX control, you must have a Web Server that will respond to client messages. To deploy your ActiveX control, use the following steps 1 Select Project I Web Deployment Options. 2 On the Project page, set the Target...

Editing package source files manually

Package source files, like project files, are generated by Delphi from information you supply. Like project files, they can also be edited manually. A package source file should be saved with the .dpk Delphi package extension to avoid confusion with other files containing Object Pascal source code. To open a package source file in the Code editor, 1 Open the package in the Package editor. 2 Right-click in the Package editor and select View Source. The package heading specifies the name for the...

Using an XML document as the client of a provider

The TXMLTransformClient component acts as an adapter to let you use an XML document or set of documents as the client for an application server or simply as the client of a dataset to which it connects via a TDataSetProvider component . That is, TXMLTransform client lets you publish database data as an XML document and to make use of update requests insertions or deletions from an external application that supplies them in the form of XML documents. To specify the provider from which the...

Scroll boxes

Scroll boxes TScrollBox create scrolling areas within a form. Applications often need to display more information than will fit in a particular area. Some controls such as list boxes, memos, and forms themselves can automatically scroll their contents. Another use of scroll boxes is to create multiple scrolling areas views in a window. Views are common in commercial word-processor, spreadsheet, and project management applications. Scroll boxes give you the additional flexibility to define...

Deleting persistent field components

Deleting a persistent field component is useful for accessing a subset of available columns in a table, and for defining your own persistent fields to replace a column in a table. To remove one or more persistent field components for a dataset 1 Select the field s to remove in the Fields editor list box. Note You can also delete selected fields by invoking the context menu and choosing Delete. Fields you remove are no longer available to the dataset and cannot be displayed by data-aware...

Viewing and editing data with TDBGrid

A TDBGrid control lets you view and edit records in a dataset in a tabular grid format. Figure 15.1 TDBGrid control Current field Three factors affect the appearance of records displayed in a grid control Existence of persistent column objects defined for the grid using the Columns editor. Persistent column objects provide great flexibility setting grid and data appearance. For information on using persistent columns, see Creating a customized grid on page 15-16. Creation of persistent field...

Registering the application server

Before client applications can locate and use an application server, it must be registered or installed. This is not strictly true for CORBA application servers, although registration is still recommended. If the application server uses DCOM, HTTP, or sockets as a communication protocol, it acts as an Automation server and must be registered like any other COM server. For information about registering a COM server, see Registering a COM object on page 36-16. If you are using a transactional...

Using decision grids

The decision grid component, TDecisionGrid, displays data from decision cubes TDecisionCube bound to decision sources TDecisionSource . By default, the grid appears with dimension fields at its left side and or top, depending on the grouping instructions defined in the dataset. Categories, one for each data value, appear under each field. You can Reorganize, or pivot, rows and columns Limit dimension selection to a single dimension for each axis For more information about special properties and...

Open String

An OpenString is obsolete, but you may see it in older code. It is for 16-bit compatibility and is allowed only in parameters. OpenString was used, before long strings were implemented, to allow a short string of an unspecified length string to be passed as a parameter. For example, this declaration will allow any length string to be passed as a parameter, where normally the string length of the formal and actual parameters must match exactly. You should not have to use OpenString in any new...