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

Working with array fields

Array fields consist of a set of fields of the same type. The field types can be scalar (for example, float, string), or non-scalar (an ADT), but an array field of arrays is not permitted. The SparseArrays property of TDataSet determines whether a unique TField object is created for each element of the array field. There are a variety of ways to access the data in array field types. If you are not using persistent fields, the dataset's ObjectView property must be set to True before you can...

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

Onedimensional crosstabs

One-dimensional crosstabs show a summary row (or column) for the categories of a single dimension. For example, if Payment is the chosen column dimension and Amount Paid is the summary category, the crosstab in Figure 16.2 shows the amount paid using each method. Figure 16.2 One-dimensional crosstab

About crosstabs

Cross-tabulations, or crosstabs, are a way of presenting subsets of data so that relationships and trends are more visible. Table fields become the dimensions of the crosstab while field values define categories and summaries within a dimension. You can use the decision support components to set up crosstabs in forms. TDecisionGrid shows data in a table, while TDecisionGraph charts it graphically. TDecisionPivot has buttons that make it easier to display and hide dimensions and move them...

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

Using a picture graphic or canvas

There are three kinds of classes in Delphi that deal with graphics A canvas represents a bitmapped drawing surface on a form, graphic control, printer, or bitmap. A canvas is always a property of something else, never a standalone class. A graphic represents a graphic image of the sort usually found in a file or resource, such as a bitmap, icon, or metafile. Delphi defines classes TBitmap, TIcon, and TMetafile, all descended from a generic TGraphic. You can also define your own graphic classes....

Design time

This chapter describes the steps for making the components you create available in the IDE. Making your components available at design time requires several steps Providing Help for your component Compiling components into packages Not all these steps apply to every component. For example, if you don't define any new properties or events, you don't need to provide Help for them. The only steps that are always necessary are registration and compilation. Once your components have been registered...

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

Communicating with the Help Manager

ICustomHelpViewer provides four functions that can be used to communicate system The Help Manager calls through these functions in the following circumstances String is called when the Help Manager wants to know the name of the viewer (for example, if the application is asked to display a list of all registered viewers). This information is returned via a string, and is required to be logically static (that is, it cannot change during the operation of the application). Multibyte character sets...

Making a control a dockable child

Note Drag and dock properties are available in the VCL but not CLX. 1 Set its DragKind property to dkDock. When DragKind is dkDock, dragging the control moves the control to a new docking site or undocks the control so that it becomes a floating window. When DragKind is dkDrag (the default), dragging the control starts a drag-and-drop operation which must be implemented using the OnDragOver, OnEndDrag, and OnDragDrop events. 2 Set its DragMode to dmAutomatic. When DragMode is dmAutomatic,...

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

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

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

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

Canceling changes

An application can undo changes made to the current record at any time, if it has not yet directly or indirectly called Post. For example, if a dataset is in dsEdit mode, and a user has changed the data in one or more fields, the application can return the record back to its original values by calling the Cancel method for the dataset. A call to Cancel always returns a dataset to dsBrowse state. If the dataset was in dsEdit or dsInsert mode when your application called Cancel, it receives...

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

Drawing ownerdrawn items

When you indicate that a control is owner-drawn, either by setting a property or supplying a custom draw event handler, the control is no longer drawn on the screen. Instead, the operating system generates events for each visible item in the control. Your application handles the events to draw the items. To draw the items in an owner-draw control, do the following for each visible item in the control. Use a single event handler for all items. Items of the same size (for example, with a list box...

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

Resizing the cells

VCL When a user or application changes the size of a window or control, Windows sends a message called WM_SIZE to the affected window or control so it can adjust any settings needed to later paint its image in the new size. Your VCL component can respond to that message by altering the size of the cells so they all fit inside the boundaries of the control. To respond to the WM_SIZE message, you will add a message-handling method to the component. Creating a message-handling method is described...

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

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

Reraising the exception

Sometimes when you handle an exception locally, you actually want to augment the handling in the enclosing block, rather than replacing it. Of course, when your local handler finishes its handling, it destroys the exception instance, so the enclosing block's handler never gets to act. You can, however, prevent the handler from destroying the exception, giving the enclosing handler a chance to respond. Example When an exception occurs, you might want to display a message to the user or record...

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

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

Deploying type libraries

By default, when you have a type library that was created as part of an ActiveX or Automation server project, the type library is automatically linked into the .DLL, .OCX, or EXE as a resource. You can, however, deploy your application with the type library as a separate .TLB, as Delphi maintains the type library, if you prefer. Historically, type libraries for Automation applications were stored as a separate file with the .TLB extension. Now, typical Automation applications compile the type...

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

Decision cube properties and events

The DimensionMap properties of TDecisionCube not only control which dimensions and summaries appear but also let you set date ranges and specify the maximum number of dimensions the decision cube may support. You can also indicate whether or not to display data during design. You can display names, categories values, subtotals, or data. Display of data at design time can be time consuming, depending on the data source. When you click the ellipsis next to DimensionMap in the Object Inspector,...

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

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

Publishing inherited properties

The abstract grid component, TCustomGrid, provides a large number of protected properties. You can choose which of those properties you want to make available to users of the calendar control. To make inherited protected properties available to users of your components, redeclare the properties in the published part of your component's declaration. For the calendar control, publish the following properties and events, as shown here TSampleCalendar class TCustomGrid published property Align...

Understanding providerbased multitiered applications

Delphi's support for multi-tiered applications use the components on the DataSnap page and the Data Access page of the component palette, plus a remote data module that is created by a wizard on the Multitier page of the New Items dialog. They are based on the ability of provider components to package data into transportable data packets and handle updates received as transportable delta packets. Understanding p r o v i d e r - b a s e d multi-tiered applications The components needed for a...

How CLX controls process Help

All controls that derive from TControl expose four properties which are used by the Help system HelpType, HelpFile, HelpContext, and HelpKeyword. HelpFile is supposed to contain the name of the file in which the control's help is located if the help is located in an external Help system that does not care about file names say, for example, the Man page system , then the property should be left blank. The HelpType property contains an instance of an enumerated type which determines if the...

Specifying custom constraints

You can use the properties of the client dataset's field components to impose your own constraints on what data users can enter. Each field component has two properties that you can use to specify constraints The DefaultExpression property defines a default value that is assigned to the field if the user does not enter a value. Note that if the database server or source dataset also assigns a default expression for the field, the client dataset's version takes precedence because it is assigned...

Web modules

The Web application module TWebAppPageModule or TWebAppDataModule is a container for the application components that perform functions for the application as a whole such as dispatching requests, managing sessions, and maintaining user lists. Your project can contain only one of these types of application modules. The Web page module TWebPageModule provides content to a page and the Web data module TWebDataModule acts as a container for components shared across your application. You can...