Renaming a file

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

Navigating data in client datasets

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

Deploying applications 1

Once your Kylix application is up and running, you can deploy it. That is, you can make it available for others to run. A number of steps must be taken to deploy an application to another computer so that the application is completely functional. The steps required by a given application vary, depending on the type of application. The following sections describe those steps for deploying applications Deploying general applications Deploying database applications Programming for varying host...

Setting text alignment

In a memo component, text can be left- or right-aligned, or centered. To change text alignment, set the edit component's Alignment property. Alignment takes effect only if the WordWrap property is True if word wrapping is turned off, there is no margin to align to. WordWrap turns wordwrapping on and off. When on, the WrapMode, WrapBreak, and WrapAtValue properties allow fine-grain control on how the wrapping is done. You can also use the HMargin property to adjust the left and right margins in...

Reading and writing over socket connections

The reason you form socket connections to other machines is so that you can read or write information over those connections. What information you read or write, or when you read it or write it, depends on the service associated with the socket connection. Reading and writing over sockets can occur asynchronously, so that it does not block the execution of other code in your network application. This is called a non-blocking connection. You can also form blocking connections, where your...

Representing the records in a table

When you want to represent all of the fields and all of the records in a single underlying database table, you can use either TSQLDataSet or TSQLTable to generate the query for you rather than writing the SQL yourself. Note If server performance is a concern, you may want to compose the query explicitly rather than relying on an automatically-generated query. Automatically-generated queries use wildcards rather than explicitly listing all of the fields in the table. This results in slightly...

Creating HTTP response messages

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

Responding with events

When a client component or control is clicked or otherwise acted on, a series of events occurs to which you can respond. For example, the following code illustrates the event handler for an action that toggles the visibility of a toolbar when the action is executed procedure TForml.ActionlExecute Sender TObject begin Toggle Toolbarl's visibility ToolBarl.Visible not ToolBarl.Visible end Note For general information about events and event handlers, see Working with events and event handlers on...

Manipulating menu items at runtime

Sometimes you want to add menu items to an existing menu structure while the application is running, to provide more information or options to the user. You can insert a menu item by using the menu item's Add or Insert method, or you can alternately hide and show the items in a menu by changing their Visible property. The Visible property determines whether the menu item is displayed in the menu. To dim a menu item without hiding it, use the Enabled property. For examples that use the menu...

Predefined action classes

The Action List editor lets you use predefined action classes that automatically perform actions. The predefined actions fall into the following categories Table 6.1 Action categories Category Description Standard edit actions Used with an edit control target. TEditAction is the base class for descendants that each override the ExecuteTarget method to implement copy, cut, and paste tasks by using the clipboard. Standard window Used with forms as targets in an MDI application. TWindowAction is...

Representing the results of a stored procedure

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

Specifying a default project new form and main form

By default, when you choose FilelNew Application or FilelNew Form, Kylix displays a blank form. You can change this behavior by reconfiguring the Repository 2 If you want to specify a default project, select the Projects page and choose an item under Objects. Then select the New Project check box. 3 If you want to specify a default form, select a Repository page such as Forms , them choose a form under Objects. To specify the default new form Filel New Form , select the New Form check box. To...

Adding a clipboard to an application

Most text-handling applications provide users with a way to move selected text between documents, including documents in different applications. The TClipboard object in Kylix provides a clipboard and includes methods for cutting, copying, and pasting text and other formats, including graphics . The TClipboard object is declared in the QClipbrd unit. To add a TClipboard object to an application, 1 Select the unit that will use the clipboard. 2 Search for the implementation reserved word. 3 Add...

Accessing field values with a datasets FieldByName method

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

Text controls

Many applications present text to the user or allow the user to enter text. The type of control used for this purpose depends on the size and format of the information. Use this component When you want users to do this TEdit Edit a single line of text. TMemo Edit multiple lines of text. TMaskEdit Adhere to a particular format, such as a postal code or phone number. TEdit and TMaskEdit are simple text controls that include a single line text edit box in which you can type information. When the...

Localizing applications

Once your application is internationalized, you can create localized versions for the different foreign markets in which you want to distribute it. Ideally, your resources have been isolated into a resource module that contains form files. You can open your forms in the IDE, translate the relevant properties, then compile the application. You can extract any resources needed using the resbind command line utility located in kylix bin. Resbind extracts the Borland resources from your application...

Component Library for Cross Platform CLX

Kylix's components are all part of a class hierarchy called the Component Library for Cross Platform CLX . Refer to Chapter 3 for more information about CLX basics. Figure 24.1 shows the relationship of selected classes that make up CLX. For a more detailed discussion of class hierarchies and the inheritance relationships among classes, see Chapter 25, Object-oriented programming for component writers. The TComponent class is the shared ancestor of every component in CLX. TComponent provides...

Nonblocking connections

Non-blocking connections read and write asynchronously, so that the transfer of data does not block the execution of other code in you network application. To create a non-blocking connection On client sockets, set the BlockMode property to bmNonBlocking. On server sockets, set the BlockMode property to bmNonBlocking. When the connection is non-blocking, reading and writing events inform your socket when the socket on the other end of the connection tries to read or write information.

Silent exceptions

Kylix applications handle most exceptions that your code doesn't specifically handle by displaying a message box that shows the message string from the exception object. You can also define silent exceptions that do not, by default, cause the application to show the error message. Silent exceptions are useful when you don't intend to report an exception to the user, but you want to abort an operation. Aborting an operation is similar to using the Break or Exit procedures to break out of a...

Using socket components

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

Using TSQLMonitor to monitor SQL commands

TSQLConnection uses a companion component, TSQLMonitor, to intercept these messages and save them in a string list. To use TSQLMonitor, 1 Add a TSQLMonitor component to the form or data module containing the TSQLConnection component whose SQL commands you want to monitor. 2 Set its SQLConnection property to the TSQLConnection component. 3 Set the SQL monitor's Active property to True. As SQL commands are sent to the server, the SQL monitor's TraceList property is automatically updated to list...

Responding to socket events

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

Working with reference fields

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

Using a client dataset with a provider

When using a client dataset to represent data from a database server or another dataset, the client dataset uses a provider component. The provider component passes data from a source dataset to the client dataset. When using TSQLClientDataSet, this source dataset is an internal query component for accessing the data with TClientDataSet, it is a dataset component you add to a form or data module. After editing the data in memory, the client dataset applies updates, through the provider, back to...

Property categories

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

Using a client dataset with data stored on disk

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

The Web dispatcher

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

Setting up masterdetail relationships

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