Working at the application level

The global variable Application, of type TApplication, is in every VCL- or CLX-based application. Application encapsulates your application as well as providing many functions that occur in the background of the program. For instance, Application handles how you call a Help file from the menu of your program. Understanding how TApplication works is more important to a component writer than to developers of stand-alone applications, but you should set the options that Application handles in the...

Dual interfaces

A dual interface is a custom interface and a dispinterface at the same time. It is implemented as a COM VTable interface that derives from IDispatch. For those controllers that can access the object only at runtime, the dispinterface is available. For objects that can take advantage of compile-time binding, the more efficient VTable interface is used. Dual interfaces offer the following combined advantages of VTable interfaces and dispinterfaces For VTable interfaces, the compiler performs type...

Avoiding simultaneous access

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

Associating property page controls with ActiveX control properties

After adding the controls you need to the property page, you must associate each control with its corresponding property. You make this association by adding code to the property page's UpdatePropertyPage and UpdateObject methods. Add code to the UpdatePropertyPage method to update the control on the property page when the properties of the ActiveX control change. You must add code to the UpdatePropertyPage method to update the property page with the current values of the ActiveX control's...

Stream methods for reading and writing

The Read method reads a specified number of bytes from the stream, starting at its current Position, into a buffer. Read then advances the current position by the number of bytes actually transferred. The prototype for Read is function Read(var Buffer Count Longint) Longint Read is useful when the number of bytes in the file is not known. Read returns the number of bytes actually transferred, which may be less than Count if the stream did not contain Count bytes of data past the current...

Rolebased security

MTS and COM+ provide role-based security where you assign a role to a logical group of users. For example, a medical information application might define roles for Physician, X-ray technician, and Patient. You define authorization for each object and interface by assigning roles. For example, in the physicians' medical application, only the Physician may be authorized to view all medical records the X-ray Technician may view only X-rays and Patients may view only their own medical record....

Diagram Editor

The Diagram Editor is used to modify UML diagrams created from the Diagrams view of the collections pane. It offers a rich collection of tools for making visual changes to your UML diagrams. You can also expand your ModelMaker model by adding features (such as properties and methods) to your UML diagrams. Model changes you make through diagrams will propagate to your source code. 01 j Navigation and IDE integration j B Ql 9 * M I& Bl --> -o k> d a a - is si 01 j Navigation and IDE...

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

Using type library tools

The tools for working with type libraries are listed below. The TLIBIMP (Type Library Import) tool, which takes existing type libraries and creates Delphi Interface files (_TLB.pas files), is incorporated into the Type Library editor. TLIBIMP provides additional configuration options not available inside the Type Library editor. TRegSvr is a tool for registering and unregistering servers and type libraries, which comes with Delphi. The source to TRegSvr is available as an example in the Demos...

Setting properties at design time

When you select a component on a form at design time, the Object Inspector displays its published properties and (when appropriate) allows you to edit them. Use the Tab key to toggle between the left-hand Property column and the right-hand Value column. When the cursor is in the Property column, you can navigate to any property by typing the first letters of its name. For properties of Boolean or enumerated types, you can choose values from a drop-down list or toggle their settings by...

Using unidirectional result sets

When a query-type dataset returns a result set, it also receives a cursor, or pointer to the first record in that result set. The record pointed to by the cursor is the currently active record. The current record is the one whose field values are displayed in data-aware components associated with the result set's data source. Unless you are using dbExpress, this cursor is bi-directional by default. A bi-directional cursor can navigate both forward and backward through its records....

Copying datasets

To copy a source dataset, the destination dataset should not represent an exist table. If it does, the batch move operation overwrites the existing table with a copy of the source dataset. If the source and destination datasets are maintained by different types of database engines, for example, Paradox and InterBase, the BDE creates a destination dataset with a structure as close as possible to that of the source dataset and automatically performs data type and size conversions as necessary....

Copying data from one stream to another

When copying data from one stream to another, you do not need to explicitly read and then write the data. Instead, you can use the CopyFrom method, as illustrated in the following example. In the following example, one file is copied to another one using streams. The application includes two edit controls (EdFrom and EdTo) and a Copy File button. procedure TForm1.CopyFileClick(Sender TObject) var Source TFileStream.Create(edFrom.Text, fmOpenRead or fmShareDenyWrite) try Destination...

COM extensions

COM was originally designed to provide core communication functionality and to enable the broadening of this functionality through extensions. COM itself has extended its core functionality by defining specialized sets of interfaces for specific purposes. The following lists some of the services COM extensions currently provide. Subsequent sections describe these services in greater detail. Automation servers Automation refers to the ability of an application to control the objects in another...

Service applications

Service applications take requests from client applications, process those requests, and return information to the client applications. They typically run in the background, without much user input. A Web, FTP, or e-mail server is an example of a service application. To create an application that implements a Win32 service 1 Choose File l New l Other, and double-click Service Application in the New Items dialog box. This adds a global variable named Application to your project, which is of type...

Using the COM Event Subscription object wizard

You can create the subscriber component using Delphi's COM+ Subscription Object wizard. To bring up the wizard, 2 Select the tab labeled ActiveX. 3 Double-click the COM+ Subscription Object icon. In the wizard dialog, enter the name of the class that will implement the event interface. Choose the threading model from the combo box. In the Interface field, you can type the name of your event interface, or click on the Browse button to bring up a list of all event classes currently installed in...

Aggregation

Sometimes, a server object makes use of another COM object to perform some of its functions. For example, an inventory management object might make use of a separate invoicing object to handle customer invoices. If the inventory management object wants to present the invoice interface to clients, however, there is a problem Although a client that has the inventory interface can call QueryInterface to obtain the invoice interface, when the invoice object was created it did not know about the...

Using Delphi or IDL syntax

The Text page of the Type Library editor displays your type information in one of two ways Using an extension of Delphi 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 Delphi...

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

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

Working with lists

BaseCLX includes many classes that represents lists or collections of items. They vary depending on the types of items they contain, what operations they support, and whether they are persistent. The following table lists various list classes, and indicates the types of items they contain Table 5.6 Classes for managing lists Table 5.6 Classes for managing lists A memory-managed list of object instances A memory-managed list of components (that is, instances of classes A first-in first-out list...

Responding to clientgenerated events

Provider components implement a general-purpose event that lets you create your own calls from client datasets directly to the provider. This is the OnDataRequest event. OnDataRequest is not part of the normal functioning of the provider. It is simply a hook to allow your client datasets to communicate directly with providers. The event handler takes an OleVariant as an input parameter and returns an OleVariant. By using OleVariants, the interface is sufficiently general to accommodate almost...

Advantages of the multitiered database model

The multi-tiered database model breaks a database application into logical pieces. The client application can focus on data display and user interactions. Ideally, it knows nothing about how the data is stored or maintained. The application server (middle tier) coordinates and processes requests and updates from multiple clients. It handles all the details of defining datasets and interacting with the database server. The advantages of this multi-tiered model include the following Encapsulation...

Defining a calculated field

A calculated field displays values calculated at runtime by a dataset's OnCalcFields event handler. For example, you might create a string field that displays concatenated values from other fields. To create a calculated field in the New Field dialog box 1 Enter a name for the calculated field in the Name edit box. Do not enter the name of an existing field. 2 Choose a data type for the field from the Type combo box. 3 Enter the size of the field in the Size edit box, if appropriate. Size is...

Working with stored procedure parameters

There are four types of parameters that can be associated with stored procedures Input parameters, used to pass values to a stored procedure for processing. Output parameters, used by a stored procedure to pass return values to an application. Input output parameters, used to pass values to a stored procedure for processing, and used by the stored procedure to pass return values to the application. A result parameter, used by some stored procedures to return an error or status value to an...

Creating projects

All 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 contained in...

Passing additional arguments to forms

Typically, you create forms for your application from within the IDE. When created this way, the forms have a constructor that takes one argument, Owner, which is the owner of the form being created. (The owner is the calling application object or form object.) Owner can be nil. To pass additional arguments to a form, create a separate constructor and instantiate the form using this new constructor. The example form class below shows an additional constructor, with the extra argument...

Creating decision datasets with the Decision Query editor

All data used by the decision support components passes through the decision cube, which accepts a specially formatted dataset most easily produced by an SQL query. See Using datasets with decision support components on page 22-5 for more information. While both TTable and TQuery can be used as decision datasets, it is easier to use TDecisionQuery the Decision Query editor supplied with it can be used to specify tables, fields, and summaries to appear in the decision cube and will help you set...

Describing sockets

Sockets let your network application communicate with other systems over the network. Each socket can be viewed as an endpoint in a network connection. It has an address that specifies The system on which it is running. The types of interfaces it understands. The port it is using for the connection. A full description of a socket connection includes the addresses of the sockets on both ends of the connection. You can describe the address of each socket endpoint by supplying both the IP address...

Deleting persistent field components

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

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