Generating a new event handler

You can generate skeleton event handlers for forms and other components. To create an event handler 2 Click the Events tab in the Object Inspector. The Events page of the Object Inspector displays all events defined for the component. 3 Select the event you want, then double-click the Value column or press Ctrl+Enter. The Code editor opens with the cursor inside the skeleton event handler, or begin end block. 4 At the cursor, type the code that you want to execute when the event occurs.

Adding a speed button to a panel

To add a speed button to a toolbar panel, place the speed button component (from the Additional page of the Component palette) on the panel. The panel, rather than the form, owns the speed button, so moving or hiding the panel also moves or hides the speed button. The default height of the panel is 41, and the default height of speed buttons is 25. If you set the Top property of each button to 8, they'll be vertically centered. The default grid setting snaps the speed button to that vertical...

Toolbars

Toolbars provide an easy way to arrange and manage visual controls. You can create a toolbar out of a panel component and speed buttons, or you can use the TToolBar component, then right-click and choose New Button to add buttons to the toolbar. The TToolBar component has several advantages buttons on a toolbar automatically maintain uniform dimensions and spacing other controls maintain their relative position and height controls can automatically wrap around to start a new row when they do...

Writing exception handlers

The exception handling block appears immediately after the try block. This block incudes one or more exception handlers. An exception handler provides a specific response to a specific kind of exception. Handling an exception clears the error condition and destroys the exception object, which allows the application to continue execution. You typically define exception handlers to allow your applications to recover from errors and continue running. Types of exceptions you might handle include...

Reading and setting pixels

You will notice that every canvas has an indexed Pixels property that represents the individual colored points that make up the image on the canvas. You rarely need to access Pixels directly, it is available only for convenience to perform small actions such as finding or setting a pixel's color. Note Setting and getting individual pixels is thousands of times slower than performing graphics operations on regions. Do not use the Pixel array property to access the image pixels of a general...

Commonly used long string routines

The long string handling routines cover several functional areas. Within these areas, some are used for the same purpose, the differences being whether they use a particular criterion in their calculations. The following tables list these routines by these functional areas Where appropriate, the tables also provide columns indicating whether a routine Uses case sensitivity If locale settings are used, it determines the definition of case. If the routine does not use locale settings, analyses...

Binding parameters

When you prepare and execute a stored procedure, its input parameters are automatically bound to parameters on the server. TStoredProc lets you use the ParamBindMode property to specify how parameters should be bound to the parameters on the server. By default ParamBindMode is set to pbByName, meaning that parameters from the stored procedure component are matched to those on the server by name. This is the easiest method of binding parameters. Some servers also support binding parameters by...

Writing an OnFilter Record event handler

You can write code to filter records using the OnFilterRecord events generated by the dataset for each record it retrieves. This event handler implements a test that determines if a record should be included in those that are visible to the application. To indicate whether a record passes the filter condition, your OnFilterRecord handler sets its Accept parameter to True to include a record, or False to exclude it. For example, the following filter displays only those records with the State...

Using the ASP intrinsics

The ASP intrinsics are a set of COM objects supplied by ASP to the objects running in an Active Server Page. They let your Active Server Object access information that reflects the messages passing between your application and the Web browser, as well as a place to store information that is shared among Active Server Objects that belong to the same ASP application. To make these objects easy to access, the base class for your Active Server Object surfaces them as properties. For a complete...

Viewing and editing data with TDBGrid

A TDBGrid control lets you view and edit records in a dataset in a tabular grid format. Figure 20.1 TDBGrid control Current field Figure 20.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...

NET components and type libraries

Both COM, and the .NET Framework contain mechanisms to expose type information. In COM, one such mechansim is the type library. Type libraries are a binary, programming language-neutral way for a COM object to expose type metadata at runtime. Because type libraries are opened and parsed by system APIs, languages such as Delphi can import them and gain the advantages of vtable binding, even if the component was written in a different programming language. In the .NET development environment, the...

Using the Web page editor

The Web page editor lets you add Web items to your InternetExpress page producer and view the resulting HTML page. Display the Web page editor by double-clicking on a InternetExpress page producer component. Note You must have Internet Explorer 4 or better installed to use the Web page editor. The top of the Web page editor displays the Web items that generate the HTML document. These Web items are nested, where each type of Web item assembles the HTML generated by its subitems. Different types...

Valid types

In the Type Library editor, you use different type identifiers, depending on whether you are working in IDL or Delphi. Specify the language you want to use in the Environment options dialog. The following types are valid in a type library for COM development. The Automation compatible column specifies whether the type can be used by an interface that has its Automation or Dispinterface flag checked. These are the types that COM can marshal via the type library automatically. Word, LongWord,...

TControl branch

The TControl branch consists of components that descend from TControl but not TWinControl (TWidgetControl in CLX applications). Classes in this branch are controls visual objects that the user can see and manipulate at runtime. All controls have properties, methods, and events in common that relate to how the control looks, such as its position, the cursor associated with the control's window, methods to paint or move the control, and events to respond to mouse actions. Controls in this branch,...

Communicating with the Help Manager

The ICustomHelpViewer provides four functions that can be used to communicate system information with the Help Manager 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...

Creating Web server applications with Web Snap

If you look at the source code for WebSnap, you will discover that WebSnap comprises hundreds of objects. In fact, WebSnap is so rich in objects and features that you could spend a long time studying its architecture in detail before understanding it completely. Fortunately, you really don't need to understand the whole WebSnap system before you start developing your server application. Here you will learn more about how WebSnap works by creating a new Web server application. To create a new...

Figures

3.1 A simplified hierarchy diagram 3-5 4.1 A simple form 4-3 9.1 A frame with data-aware controls and a data source component 9-16 9.3 Menu terminology 9-32 9.4 MainMenu and PopupMenu components 9-33 9.6 Adding menu items to a main menu . . .9-36 9.7 Nested menu structures 9-37 10.2 A progress bar 10-15 11.1 Part of the ModelMaker toolbar 11-3 11.2 ModelMaker showing a sample 11.3 The Classes view 11-5 11.4 The Units view 11-5 11.5 The Diagrams view 11-6 11.6 The Members view 11-7 11.7 The...

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 TransIsolation to DirtyRead if not (Databasel.IsSQLBased) and not (Databasel.Translsolation tiDirtyRead) then Databasel.Translsolation...

Object pooling

Just as you can pool resources, under COM+ you can also pool objects. When an object is deactivated, COM+ calls the IObjectControl interface method, CanBePooled, which indicates that the object can be pooled for reuse. If CanBePooled is returns True, then instead of being destroyed on deactivation, the object is moved to the object pool. It remains in the object pool for a specified time-out period, during which time it is available for use to any client requesting it. Only when the object pool...

Events with client connections

When a server socket accepts a client connection request, the following events occur An OnAccept event occurs, passing in the new TTcpClient object to the event handler. This is the first point when you can use the properties of TTcpClient to obtain information about the server endpoint of the connection to a client. If BlockMode is bmThreadBlocking an OnGetThread event occurs. If you want to provide your own customized descendant of TServerSocketThread, you can create one in an OnGetThread...

Graphic controls

The following components make it easy to incorporate graphics into an application. Use this component To display TPaintBox Graphics drawn by your program at runtime TAnimate AVI files (VCL applications only) GIF files (CLX applications only) Notice that these include common paint routines (Repaint, Invalidate, and so on) that never need to receive focus. To create a graphic control, see Chapter 10, Creating a graphic control, in the Component Writer's Guide.

Registering Help system objects

For the Help Manager to communicate with them, objects that implement ICustomHelpViewer, IExtendedHelpViewer, ISpecialWinHelpViewer, and IHelpSelector must register with the Help Manager. To register Help system objects with the Help Manager, you need to Register the Help Selector. The unit that contains the object implementation must use HelpIntfs. An instance of the object must be declared in the var section of the implementing unit. The initialization section of the implementing unit must...

Converting userdefined nodes

When you define a transformation using xmlmapper.exe, you can specify that some of the nodes in the XML document are user-defined. User-defined nodes are nodes for which you want to provide the transformation in code rather than relying on a straightforward node-value-to-field-value translation. You can provide the code to translate user-defined nodes using the OnTranslate event. The OnTranslate event handler is called every time the TXMLTransform component encounters a user-defined node in the...

Login support

Many Web server applications require login support. For example, a server application may require a user to login before granting access to some parts of a Web site. Pages may have a different appearance for different users logins may be necessary to enable the Web server to send the right pages. Also, because servers have physical limitations on memory and processor cycles, server applications sometimes need the ability to limit the number of users at any given time. With WebSnap,...

Initializing the thread

If you want to write initialization code for your new thread class, you must override the Create method. Add a new constructor to the declaration of your thread class and write the initialization code as its implementation. This is where you can assign a default priority for your thread and indicate whether it should be freed automatically when it finishes executing. Priority indicates how much preference the thread gets when the operating system schedules CPU time among all the threads in your...

Using the XML Data Binding wizard

1 Choose File I New I Other and select the icon labeled XML Data Binding from the bottom of the New page. 2 The XML Data Binding wizard appears. 3 On the first page of the wizard, specify the XML document or schema for which you want to generate interfaces. This can be a sample XML document, a Document Type Definition (.dtd) file, a Reduced XML Data (.xdr) file, or an XML schema (.xsd) file. 4 Click the Options button to specify the naming strategies you want the wizard to use when generating...

Mixing and converting string types

Short, long, and wide strings can be mixed in assignments and expressions, and the compiler automatically generates code to perform the necessary string type conversions. However, when assigning a string value to a short string variable, be aware that the string value is truncated if it is longer than the declared maximum length of the short string variable. Long strings are already dynamically allocated. If you use one of the built-in pointer types, such as PAnsiString, PString, or...

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

Setting maximum dimensions summaries and cells

The decision cube's MaxDimensions and MaxSummaries properties can be used with the CubeDim.ActiveFlag property to control how many dimensions and summaries can be loaded at a time. You can set the maximum values on the Cube Capacity page of the Decision Cube editor to place some overall control on how many dimensions or summaries can be brought into memory at the same time. Limiting the number of dimensions or summaries provides a rough limit on the amount of memory used by the decision cube....

Setting tool button appearance and initial conditions

Table 9.8 lists some actions you can set to change a tool button's appearance Table 9.8 Setting tool buttons' appearance To make a tool button Set the toolbar's Appear pressed (on tool button) Style property to tbsCheck and Appear disabled Enabled property to False. Have a left margin Indent property to a value greater than 0. Appear to have pop-up borders, thus making Flat property to True. Note Using the Flat property of TToolBar requires version 4.70 or later of COMCTL32.DLL. To force a new...

Creating type libraries

With traditional development tools, you create type libraries by writing scripts in the Interface Definition Language (IDL) or the Object Description Language (ODL), then running that script through a compiler. However, Delphi automatically generates a type library when you create a COM object (including ActiveX controls, Automation objects, remote data modules, and so on) using any of the wizards on the ActiveX or Multitier page of the new items dialog. (You can opt not to create a type...

Implementing IExtended HelpViewer

ICustomHelpViewer only provides direct support for keyword-based Help. Some Help systems (especially WinHelp) work by associating numbers (known as context IDs) with keywords in a fashion which is internal to the Help system and therefore not visible to the application. Such systems require that the application support context-based Help in which the application invokes the Help system with that context, rather than with a string, and the Help system translates the number itself. Applications...

Controlling how child controls are docked

A docking site automatically accepts child controls when they are released over the docking site. For most controls, the first child is docked to fill the client area, the second splits that into separate regions, and so on. Page controls dock children into new tab sheets (or merge in the tab sheets if the child is another page control). Three events allow docking sites to further constrain how child controls are docked property OnGetSitelnfo TGetSitelnfoEvent TGetSitelnfoEvent procedure(Sender...

Importing type library information

To make information about the COM server available to your client application, you must import the information about the server that is stored in the server's type library. Your application can then use the resulting generated classes to control the server object. There are two ways to import type library information You can use the Import Type Library dialog to import all available information about the server types, objects, and interfaces. This is the most general method, because it lets you...

Managing layout

At its simplest, you control the layout of your user interface by where you place controls in your forms. The placement choices you make are reflected in the control's Top, Left, Width, and Height properties. You can change these values at runtime to change the position and size of the controls in your forms. Controls have a number of other properties, however, that allow them to automatically adjust to their contents or containers. This allows you to lay out your forms so that the pieces fit...

Specifying default database connection behavior

KeepConnections provides the default value for the KeepConnection property of implicit database components created at runtime. KeepConnection specifies what happens to a database connection established for a database component when all its datasets are closed. If True (the default), a constant, or persistent, database connection is maintained even if no dataset is active. If False, a database connection is dropped as soon as all its datasets are closed. Note Connection persistence for a...

Indicating the types of operations the connection supports

ADO connections are established using a specific mode, similar to the mode you use when opening a file. The connection mode determines the permissions available to the connection, and hence the types of operations (such as reading and writing) that can be performed using that connection. Use the Mode property to indicate the connection mode. The possible values are listed in Table 27.3 Permissions are not yet set for the connection or cannot be determined. Read-only permissions are available to...

The structure of the application server

When you set up and run an application server, it does not establish any connection with client applications. Rather, client applications initiate and maintain the connection. The client application uses a connection component to connect to the application server, and uses the interface of the application server to communicate with a selected provider. All of this happens automatically, without your having to write code to manage incoming requests or supply interfaces. The basis of an...

Automation object wrappers

The wrappers for Automation objects let you control how you want to form the connection to your server object The ConnectKind property indicates whether the server is local or remote and whether you want to connect to a server that is already running or if a new instance should be launched. When connecting to a remote server, you must specify the machine name using the RemoteMachineName property. Once you have specified the ConnectKind, there are three ways you can connect your component to the...

Supplying parameters at design time

At design time, you can specify parameter values using the parameter collection editor. To display the parameter collection editor, click on the ellipsis button for the Params or Parameters property in the Object Inspector. If the SQL statement does not contain any parameters, no objects are listed in the collection editor. Note The parameter collection editor is the same collection editor that appears for other collection properties. Because the editor is shared with other properties, its...

Using ports

While the IP address provides enough information to find the system on the other end of a socket connection, you also need a port number on that system. Without port numbers, a system could only form a single connection at a time. Port numbers are unique identifiers that enable a single system to host multiple connections simultaneously, by giving each connection a separate port number. Earlier, we described port numbers as numeric codes for the services implemented by network applications....

Objects components and controls

Figure 3.2 is a greatly simplified view of the inheritance hierarchy that illustrates the relationship between objects, components, and controls. Figure 3.1 A simplified hierarchy diagram Figure 3.1 A simplified hierarchy diagram TPersistent ) TComponent V-TControl TPersistent ) TComponent V-TControl Objects ( TGraphicControM Objects * TWidgetControl in cross-platform applications. Every object (class) inherits from TObject. Objects that can appear in the Form Designer inherit from TPersistent...

Specifying the table type for local tables

If an application accesses Paradox, dBASE, FoxPro, or comma-delimited ASCII text tables, then the BDE uses the TableType property to determine the table's type (its expected structure). TableType is not used when TTable represents an SQL-based table on a database server. By default TableType is set to ttDefault. When TableType is ttDefault, the BDE determines a table's type from its filename extension. Table 26.1 summarizes the file extensions recognized by the BDE and the assumptions it makes...

Controlling an Automation server using a dispatch interface

Typically, you use the dual interface to control the Automation server, as described above. However, you may find a need to control an Automation server with a dispatch interface because no dual interface is available. To call the methods of a dispatch interface, 1 Connect to the server, using the global CreateOleObject function. 2 Use the as operator to cast the IDispatch interface returned by CreateOleObject to the dispinterface for the CoClass. This dispinterface type is declared in the...

The structure of a Web Broker application

When the Web application receives an HTTP request message, it creates a TWebRequest object to represent the HTTP request message, and a TWebResponse object to represent the response that should be returned. The application then passes these objects to the Web dispatcher (either the Web module or a TWebDispatcher component). The Web dispatcher controls the flow of the Web server application. The dispatcher maintains a collection of action items (TWebActionltem) that know how to handle certain...

Using the Document Object Model

The Document Object Model (DOM) is a set of standard interfaces for representing a parsed XML document. These interfaces are implemented by a number of different third-party vendors. If you do not want to use the default vendor that ships with Delphi, there is a registration mechanism that lets you integrate additional DOM implementations by other vendors into the XML framework. The XMLDOM unit includes declarations for all the DOM interfaces defined in the W3C XML DOM level 2 specification....

Sending and receiving headers

Once you have defined and registered header classes, they are available for your application to use. When your application receives a request, the headers on that message are automatically converted into the corresponding TSOAPHeader descendants that you have defined. Your application identifies the appropriate header class by matching the name of the header node against the type name you used when you registered the header class. Any headers for which it can't find a match in the remotable...

Getting started

You can use Rave Reports in both VCL and CLX applications to generate reports from database and non-database data. The following procedure explains how to add a simple report to an existing database application. 1 Open a database application in Delphi. 2 From the Rave page of the Component palette, add the TRvDataSetConnection component to a form in the application. 3 In the Object Inspector, set the DataSet property to a dataset component that is already defined in your application. 4 Use the...

Using update objects to update a dataset

When the BDE-enabled dataset represents a stored procedure or a query that is not live, it is not possible to apply updates directly from the dataset. Such datasets may also cause a problem when you use a client dataset to cache updates. Whether you are using the BDE or a client dataset to cache updates, you can handle these problem datasets by using an update object 1 If you are using a client dataset, use an external provider component with TClientDataSet rather than TBDEClientDataSet. This...

Adding images to menu items

Images can help users navigate in menus by matching glyphs and images to menu item action, similar to toolbar images. You can add single bitmaps to menu items, or you can organize images for your application into an image list and add them to a menu from the image list. If you're using several bitmaps of the same size in your application, it's useful to put them into an image list. To add a single image to a menu or menu item, set its Bitmap property to reference the name of the bitmap to use...

Creating packages and DLLs

Dynamic link libraries (DLLs) are modules of compiled code that work in conjunction with an executable to provide functionality to an application. You can create DLLs in cross-platform programs. However, on Linux, DLLs (and packages) recompile as shared objects. DLLs and libraries should handle all exceptions to prevent the display of errors and warnings through Windows dialogs. The following compiler directives can be placed in library project files Table 8.1 Compiler directives for libraries...

Elements of an ActiveX control

An ActiveX control involves many elements which each perform a specific function. The elements include a VCL control, a corresponding COM object wrapper that exposes properties, methods, and events, and one or more associated type libraries. The underlying implementation of an ActiveX control in Delphi is a VCL control. When you create an ActiveX control, you must first design or choose the VCL control from which you will make your ActiveX control. The underlying VCL control must be a...

Connecting a property page to an ActiveX control

To connect a property page to an ActiveX control, 1 Add DefinePropertyPage with the GUID constant of the property page as the parameter to the DefinePropertyPages method implementation in the control's implementation for the unit. For example, procedure TDefinePropertyPage) begin end The GUID constant, Class_PropertyPage1, of the property page can be found in the property pages unit. The GUID is defined in the property page's implementation unit it is generated automatically by the Property...

Adding new measurement types

If you want to perform conversions between measurement units not already defined in the StdConvs unit, you need to create a new conversion family to represent the measurement units (TConvType values). When two TConvType values are registered with the same conversion family, the Convert function can convert between measurements made using the units represented by those TConvType values. You first need to obtain TConvFamily values by registering a conversion family using the...

Creating a customized grid

A customized grid is one for which you define persistent column objects that describe how a column appears and how the data in the column is displayed. A customized grid lets you configure multiple grids to present different views of the same dataset (different column orders, different field choices, and different column colors and fonts, for example). A customized grid also enables you to let users modify the appearance of the grid at runtime without affecting the fields used by the grid or...

Handling server constraints

Most relational database management systems implement constraints on their tables to enforce data integrity. A constraint is a rule that governs data values in tables and columns, or that governs data relationships across columns in different tables. For example, most SQL-92 compliant relational databases support the following constraints NOT NULL, to guarantee that a value supplied to a column has a value. NOT NULL UNIQUE, to guarantee that column value has a value and does not duplicate any...

Creating and editing standard data modules

To create a standard data module for a project, choose FilelNew l Data Module. The IDE opens a data module container on the desktop, displays the unit file for the new module in the Code editor, and adds the module to the current project. At design time, a data module looks like a standard form with a white background and no alignment grid. As with forms, you can place nonvisual components from the Component palette onto a module, and edit their properties in the Object Inspector. You can...

How VCL controls process Help

All VCL controls that derive from TControl expose several properties that are used by the Help system HelpType, HelpContext, and HelpKeyword. The HelpType property contains an instance of an enumerated type that determines if the control's designer expects help to be provided via keyword-based Help or context-based Help. If the HelpType is set to htKeyword, then the Help system expects the control to use keyword-based Help, and the Help system only looks at the contents of the HelpKeyword...

Advanced HTML design

Using adapters and adapter page producers, WebSnap makes it easy to create scripted HTML pages in your Web server application. You can create a Web front end for your application data using WebSnap tools that may suit all of your needs. One powerful feature of WebSnap, however, is the ability to incorporate Web design expertise from other sources into your application. This section discusses some strategies for expanding the Web server design and maintenance process to include other tools and...

Mapping data types

In batAppend mode, a batch move component creates the destination table based on the column data types of the source table. Columns and types are matched based on their position in the source and destination tables. That is, the first column in the source is matched with the first column in the destination, and so on. To override the default column mappings, use the Mappings property. Mappings is a list of column mappings (one per line). This listing can take one of two forms. To map a column...

Creating and managing menus

Menus provide an easy way for your users to execute logically grouped commands. The Menu Designer enables you to easily add a menu either predesigned or custom tailored to your form. You add a menu component to the form, open the Menu Designer, and type menu items directly into the Menu Designer window. You can add or delete menu items, or drag and drop them to rearrange them during design time. You don't even need to run your program to see the results your design is immediately visible in the...

Accepting dragged items

When the user drags something over a control, that control receives an OnDragOver event, at which time it must indicate whether it can accept the item if the user drops it there. The drag cursor changes to indicate whether the control can accept the dragged item. To accept items dragged over a control, attach an event handler to the control's OnDragOver event. The drag-over event has a parameter called Accept that the event handler can set to True if it will accept the item. Accept changes the...

Creating an OnUpdate Record event handler

When a BDE-enabled dataset applies its cached updates, it iterates through the changes recorded in its cache, attempting to apply them to the corresponding records in the base table. As the update for each changed, deleted, or newly inserted record is about to be applied, the dataset component's OnUpdateRecord event fires. Providing a handler for the OnUpdateRecord event allows you to perform actions just before the current record's update is actually applied. Such actions can include special...

Blocking connections

When the connection is blocking, your socket must initiate reading or writing over the connection. It cannot wait passively for a notification from the socket connection. Use a blocking socket when your end of the connection is in charge of when reading and writing takes place. For client or server sockets, set the BlockMode property to bmBlocking to form a blocking connection. Depending on what else your client application does, you may want to create a new execution thread for reading or...

Building an Internet Express application

The following steps describe one way to build a Web application using InternetExpress. The result is an application that creates HTML pages that let users interact with the data from an application server via a javascript-enabled Web browser. You can also build an InternetExpress application using the Site Express architecture by using the InternetExpress page producer (TInetXPageProducer). 1 Choose File l New l Other to display the New Items dialog box, and on the New page select Web Server...

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

Memo and rich edit controls

Both the TMemo and TRichEdit controls handle multiple lines of text. TMemo is another type of edit box that handles multiple lines of text. The lines in a memo control can extend beyond the right boundary of the edit box, or they can wrap onto the next line. You control whether the lines wrap using the WordWrap property. TRichEdit is a memo control that supports rich text formatting, printing, searching, and drag-and-drop of text. It allows you to specify font properties, alignment, tabs,...

Remotable object example

This example shows how to create a remotable object for a parameter on an invokable interface where you would otherwise use an existing class. In this example, the existing class is a string list (TStringList). To keep the example small, it does not reproduce the Objects property of the string list. Because the new class is not scalar, it descends from TRemotable rather than TRemotableXS. It includes a published property for every property of the string list you want to communicate between the...

Adding additional properties methods and events

You can add additional properties, methods, and events to the control using the type library editor. The declaration is automatically added to the control's implementation unit, type library (TLB) file, and type library unit. The specifics of what Delphi supplies depends on whether you have added a property or method or whether you have added an event. The ActiveX wrapper class implements properties in its interface using read and write access methods. That is, the wrapper class has COM...

Defining a lookup field

A lookup field is a read-only field that displays values at runtime based on search criteria you specify. In its simplest form, a lookup field is passed the name of an existing field to search on, a field value to search for, and a different field in a lookup dataset whose value it should display. For example, consider a mail-order application that enables an operator to use a lookup field to determine automatically the city and state that correspond to the zip code a customer provides. The...

Responding to user actions at runtime

You can modify grid behavior by writing event handlers to respond to specific actions within the grid at runtime. Because a grid typically displays many fields and records at once, you may have very specific needs to respond to changes to individual columns. For example, you might want to activate and deactivate a button elsewhere on the form every time a user enters and exits a specific column. The following table lists the grid events available in the Object Inspector. OnEditButtonClick...

Converting Web server application target types

One powerful feature of Web Broker and WebSnap is that they offer several different target server types. The IDE allows you to easily convert from one target type to another. Because Web Broker and WebSnap have slightly different design philosophies, you must use a different conversion method for each architecture. To convert your Web Broker application target type, use the following steps 1 Right-click the Web module and choose Add To Repository. 2 In the Add To Repository dialog box, give...

Creating a new string list

A string list is typically part of a component. There are times, however, when it is convenient to create independent string lists, for example to store strings for a lookup table. The way you create and manage a string list depends on whether the list is short-term (constructed, used, and destroyed in a single routine) or long-term (available until the application shuts down). Whichever type of string list you create, remember that you are responsible for freeing the list when you finish with...

Specifying a query using the SQL property

When using a true query-type dataset (TQuery, TADOQuery, TSQLQuery, or TIBQuery), assign the query to the SQL property. The SQL property is a TStrings object. Each separate string in this TStrings object is a separate line of the query. Using multiple lines does not affect the way the query executes on the server, but can make it easier to modify and debug the query if you divide the statement into logical units MyQuery.SQL.Add('SELECT CustNo, OrderNO, SaleDate') MyQuery.SQL.Add(' FROM Orders')...

Apply Updates dialog

The Apply Updates dialog appears when you refresh, register, or save the type library if you have selected Display updates before refreshing in the Tools I Environment OptionslType Library page (which is on by default). Without this option, the Type Library editor automatically updates the sources of the associated object when you make changes in the editor. With this option, you have a chance to veto the proposed changes when you attempt to refresh, save, or register the type library. The...

List controls

A list with a check box in front of each item An edit box with a scrollable drop-down list A hierarchical list A list of (draggable) items with optional icons, columns, and headings A list of items or data in rows and columns displayed as either small or large icons (CLX applications only) A list box for entering dates or times (VCL applications only) A calendar for selecting dates (VCL applications only) Use the nonvisual TStringList and TImageList components to manage sets of strings and...

Importing the Word type library

1 Choose ProjectlImport Type Library. 2 In the Import Type Library dialog, a Select Microsoft Office 8.0 Object Library. If Word (Version 8) is not in the list, choose the Add button, go to Program Files Microsoft Office Office, select the Word type library file, MSWord8.olb choose Add, and then select Word (Version 8) from the list. The Install dialog appears. Select the Into New Packages tab and type WordExample to create a new package containing this type library. 3 Go to the Servers Palette...

Adding icons to menus and toolbars

You can add icons next to menu items or replace captions on toolbars with icons. You organize bitmaps or icons using an ImageList component. 1 Drop an ImageList component from the Win32 page of the Component palette onto a form. 2 Add the images you want to use to the image list Double-click the ImageList icon. Click Add and navigate to the images you want to use and click OK when done. Some sample images are included in Program Files Common Files Borland Shared Images. (The buttons images...

Refining line drawing

With fields in place to track various points, you can refine an application's line drawing. When drawing lines, track the point where the line starts with the Origin field. Origin must be set to the point where the mouse-down event occurs, so the mouse-up event handler can use Origin to place the beginning of the line, as in this code procedure TForm1.FormMouseDown(Sender TObject Button TMouseButton Shift TShiftState X, Y Integer) Drawing True Canvas.MoveTo(X, Y) Origin Point(X, Y) record where...

Creating and modifying server metadata

Most of the commands that do not return data fall into two categories those that you use to edit data (such as INSERT, DELETE, and UPDATE commands), and those that you use to create or modify entities on the server such as tables, indexes, and stored procedures. If you don't want to use explicit SQL commands for editing, you can link your unidirectional dataset to a client dataset and let it handle all the generation of all SQL commands concerned with editing (see Connecting a client dataset 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...

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 31.1. Figure 31.1 Web-based multi-tiered database application Figure 31.1 Web-based multi-tiered database application There are two approaches that you can...

Accessing client request information

When an HTTP request message is received by the Web server application, the headers of the client request are loaded into the properties of an object descended from TWebRequest. For example, in NSAPI and ISAPI applications, the request message is encapsulated by a TISAPIRequest object, and console CGI applications use TCGIRequest objects. The properties of the request object are read-only. You can use them to gather all of the information available in the client request. Properties that contain...

Creating attribute sets for field components

When several fields in the datasets used by your application share common formatting properties (such as Alignment, DisplayWidth, DisplayFormat, EditFormat, MaxValue, MinValue, and so on), it is more convenient to set the properties for a single field, then store those properties as an attribute set in the Data Dictionary. Attribute sets stored in the data dictionary can be easily applied to other fields. Note Attribute sets and the Data Dictionary are only available for BDE-enabled datasets....

Preparing the dataset

Before a query or stored procedure can execute on the server, it must first be prepared. Preparing the dataset means that dbExpress and the server allocate resources for the statement and its parameters. If CommandType is ctTable, this is when the dataset generates its SELECT query. Any parameters that are not bound by the server are folded into a query at this point. Unidirectional datasets are automatically prepared when you set Active to True or call the Open method. When you close the...

Starting a drag operation

Every control has a property called DragMode that determines how drag operations are initiated. If DragMode is dmAutomatic, dragging begins automatically when the user presses a mouse button with the cursor on the control. Because dmAutomatic can interfere with normal mouse activity, you may want to set DragMode to dmManual (the default) and start the dragging by handling mouse-down events. To start dragging a control manually, call the control's BeginDrag method. BeginDrag takes a Boolean...

GUI applications

A graphical user interface (GUI) application is one that is designed using graphical features such as windows, menus, dialog boxes, and features that make the application easy to use. When you compile a GUI application, an executable file with start-up code is created. The executable usually provides the basic functionality of your program, and simple programs often consist of only an executable file. You can extend the application by calling DLLs, packages, and other support files from the...

Responding to client data requests

Usually client requests for data are handled automatically. A client dataset or XML broker requests a data packet by calling GetRecords (indirectly, through the IAppServer interface). The provider responds automatically by fetching data from the associated dataset or XML document, creating a data packet, and sending the packet to the client. The provider has the option of editing data after it has been assembled into a data packet but before the packet is sent to the client. For example, you...

Creating tables

TTable and TIBTable both let you create the underlying database table without using SQL. Similarly, TClientDataSet lets you create a dataset when you are not working with a dataset provider. Using TTable and TClientDataSet, you can create the table at design time or runtime. TIBTable only lets you create tables at runtime. Before you can create the table, you must be set properties to specify the structure of the table you are creating. In particular, you must specify The database that will...

Creating Web Broker applications

You can use Web Broker (also called NetCLX architecture) to create Web server applications such as CGI applications or dynamic-link libraries (DLLs). These Web server applications can contain any nonvisual component. Components on the Internet page of the Component palette enable you to create event handlers, programmatically construct HTML or XML documents, and transfer them to the client. To create a new Web server application using the Web Broker architecture, choose FilelNewlOther and...

Fetching multiple datasets

Some stored procedures return multiple sets of records. The dataset only fetches the first set when you open it. In order to access the other sets of records, call the NextRecordSet method DataSet2 TCustomSQLDataSet nRows Integer begin DataSet2 SQLStoredProcl.NextRecordSet NextRecordSet returns a newly created TCustomSQLDataSet component that provides access to the next set of records. That is, the first time you call NextRecordSet, it returns a dataset for the second set of records. Calling...

Calculating fields

Using the Fields editor, you can define calculated fields for your datasets. When a dataset contains calculated fields, you provide the code to calculate those field's values in an OnCalcFields event handler. For details on how to define calculated fields using the Fields editor, see Defining a calculated field on page 25-7. The AutoCalcFields property determines when OnCalcFields is called. If AutoCalcFields is True, OnCalcFields is called when The dataset enters edit mode. A record is...

Indicating that a control is ownerdrawn

To customize the drawing of a control, you must supply event handlers that render the control's image when it needs to be painted. Some controls receive these events automatically. For example, list views, tree views, and toolbars all receive events at various stages in the drawing process without your having to set any properties. These events have names such as OnCustomDraw or OnAdvancedCustomDraw. Other controls, however, require you to set a property before they receive owner-draw events....

Using passthrough SQL

With passthrough SQL, you use a TQuery, TStoredProc, or TUpdateSQL component to send an SQL transaction control statement directly to a remote database server. The BDE does not process the SQL statement. Using passthrough SQL enables you to take direct advantage of the transaction controls offered by your server, especially when those controls are non-standard. To use passthrough SQL to control a transaction, you must Install the proper SQL Links drivers. If you chose the Typical installation...

Using Lookup

Lookup searches for the first row that matches specified search criteria. If it finds a matching row, it forces the recalculation of any calculated fields and lookup fields associated with the dataset, then returns one or more fields from the matching row. Lookup does not move the cursor to the matching row it only returns values from it. In its simplest form, you pass Lookup the name of field to search, the field value to match, and the field or fields to return. For example, the following...

Default exception handling in VCL

If your application code does not catch and handle the exceptions that are raised, the exceptions are ultimately caught and handled by the HandleException method of the global Application object. For all exceptions but EAbort, HandleException calls the OnException event handler, if one exists. If there is no OnException event handler (and the exception is not EAbort), HandleException displays a message box with the error message associated with the exception. There are certain circumstances...

Using the MoveBy method

MoveBy lets you specify how many rows forward or back to move the cursor in a dataset. Movement is relative to the current record at the time that MoveBy is called. MoveBy also sets the Bof and Eof properties for the dataset as appropriate. This function takes an integer parameter, the number of records to move. Positive integers indicate a forward move and negative integers indicate a backward move. Note MoveBy raises an exception in unidirectional datasets if you use a negative argument....

Connecting to an application server that uses multiple data modules

If a COM-based application server uses a main parent remote data module and several child remote data modules, as described in Using multiple remote data modules on page 31-21, then you need a separate connection component for every remote data module on the application server. Each connection component represents the connection to a single remote data module. While it is possible to have your client application form independent connections to each remote data module on the application server,...

Using 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). Graphed data comes from a specially formatted dataset such as TDecisionQuery. For an overview of how the decision support components handle and arrange this data, see page 22-1. By default, the first row dimension appears as the x-axis and the...

Working with field components

This chapter describes the properties, events, and methods common to the TField object and its descendants. Field components represent individual fields (columns) in datasets. This chapter also describes how to use field components to control the display and editing of data in your applications. Field components are always associated with a dataset. You never use a TField object directly in your applications. Instead, each field component in your application is a TField descendant specific to...