Creating a VCL Forms ActiveX Active Form

Like a Delphi control, an ActiveX control generates program code when you place the component on a form or other logical container in the IDE. The main difference between an ActiveX control and a Delphi control is that an ActiveX control is language independent. You can create ActiveX controls for deployment to a variety of programming environments on Windows, not just Delphi or C Builder, for example. This procedure uses the VCL forms ActiveX Active Form wizard to create an Active Form...

Deploying a NET Component to the Global Assembly Cache

The .NET Framework SDK utility called gacutil is a command-line program that is used to install, remove, and view components in the GAC. The gacutil command is usable from installation scripts as well as from batch files. The gacutil command supports installation and removal of shared assemblies, with and without the use of reference counting. It is recommended that the non-reference counted command switches be used only during development. Installation scripts that use gacutil to install...

Using COM Interfaces

When using COM interfaces, a similar approach is taken as when using unmanaged API's. The interface needs to be declared, using custom attributes to describe the type interface and the GUID. Next the methods are declared using the same approach as for unmanaged API's. The following example uses the IAutoComplete interface, defined as follows in Delphi 7 function Init hwndEdit HWND punkACL IUnknown pwszRegKeyPath LPCWSTR pwszQuickComplete LPCWSTR HRESULT stdcall function Enable fEnable BOOL...

To create an empty Interbase database using the IBConsole program

1. Start the Interbase Console program, IBConsole. 2. Login to the server where you want the new database to be created. Under the Databases node you will see a list of databases that reside on that server. 3. Right-click on the Databases node, and select Create Database. 4. Type the path and file name of the database. Customize any database parameters you wish to change, and click OK. The new database will be displayed under the Databases node in the IBConsole window. Next, you must go back to...

To use the Data Adapter Preview

1. After you have dropped a BdpDataAdapter component onto the designer, click the Configure Data Adapter designer verb that appears at the bottom of the Object Inspector. 2. Click the Preview tab to display the Data Adapter Preview. 3. To limit the number of rows fetched, click the Limit rows check box. 4. Enter the number of rows you want the result set to contain, in the Rows to fetch text box. 5. Click Refresh to re-execute the query and to refill the list box with the new number of rows.

Nested Exceptions

Code executed in an exception handler can itself raise and handle exceptions. As long as these exceptions are also handled within the exception handler, they do not affect the original exception. However, once an exception raised in an exception handler propagates beyond that handler, the original exception is lost. This is illustrated by the Tan function below. ETrigError class EMathError function Tan X Extended Extended begin try raise ETrigError.Create 'Invalid argument to Tan' end end If an...

To create a database project from the Data Explorer

1. Make sure you have a live connection to a database. 2. From the View menu, select Data Explorer. 3- Choose File New Other and select a Delphi for .NET project. 4. Expand the Data Explorer Tree by drilling down to the Table or View level. 5. Drag and drop any data onto your form. All the appropriate database components, including bdpConnection, bdpCommand, and bdpDataAdapter, appear in the component tray. 6. Specify the appropriate database properties for each database component, for...

To define primary keys for each DataTable in the DataSet

1. Select each data adapter in turn and set the Active property under Live Data in the Object Inspector to True. 2. Select the DataSet in the Component Tray. 3. In the Object Inspector, in the Tables property, click the ellipsis button. This displays the Tables Collection Editor. If you have set all of the data adapters' Active properties to True, the Tables Collection Editor will contain one member for each DataTable stored in the corresponding DataSet. 4. Select a table from the members list....

Using ActionManager to Create Actions in a VCL Forms Application

Using Delphi 8 for .NET, the following procedure illustrates how to create actions using ActionManager. It sets up a simple user interface with a text area, as would be appropriate for a text editing application, and describes how to create a file menu item with a file open action. Building the VCL application with ActionManager actions consists of the following major steps 2. Add a file open action to the ActionManager. 5. Build and run the application.

Compound Statements

A compound statement is a sequence of other simple or structured statements to be executed in the order in which they are written. The compound statement is bracketed by the reserved words begin and end, and its constituent statements are separated by semicolons. For example The last semicolon before end is optional. So we could have written this as Compound statements are essential in contexts where Delphi syntax requires a single statement. In addition to program, function, and procedure...

BorlandVCL Namespace

VCL.NET classes are found under the Borland.Vcl namespace. Database-related classes are in the Borland.Vcl.DB namespace. Runtime library classes are in the Borland.Vcl.Rtl namespace. If you are a user of earlier Delphi versions, you will find that the unit files with which you are familiar, have been bundled in corresponding Borland.Vcl namespaces. In some cases, units have been moved, however, every attempt has been made to identify the namespaces in meaningful ways, and in ways that will...

Add Web Reference

You can add a Web Reference to your client application to access Web Services applications. A Web Reference refers to either a WSDL document or an XML schema, which is imported into your client application. The WSDL document or XML schema describes a Web Service application. When you import one of these documents, Delphi 8 for .NET generates the interfaces and class definitions needed for calling that Web Service application. Right-click the WebService node in the Project Manager and select Add...

Configuring the IDE to avoid internal errors

1. Create a single directory where all of your .dcpil files precompiled package files are placed. For example, create a directory called C DCPIL and under ToolsEnvironment Options select the Library tab and set the DCPIL output directory to C DCPIL. This setting will help ensure that the .dcpil files the compiler generates are always up-to-date which is particularly useful when you move a package from one directory to another. You can create a .dcuil directory on a per-project basis using...

To connect a DataGrid to a DataSet 1

1. Drag and drop a DataGrid component onto the designer. If necessary, select DataGrid. 2. In Object Inspector, select the DataSource property drop-down. Select the DataSet component that you generated previously the default is DataSet1 . 3. In Object Inspector, select the DataMember property drop-down. Select the appropriate table. The DataGrid displays data from the DataSet. The application compiles and displays a Windows Form with DataGrid. While presenting a minimum number of steps required...

Pascal cdecl stdcall and safecall Conventions

Under the pascal, cdecl, stdcall and safecall conventions, all parameters are passed on the stack. Under the pascal convention, parameters are pushed in the order of their declaration left-to-right , so that the first parameter ends up at the highest address and the last parameter ends up at the lowest address. Under the cdecl, stdcall, and safecall conventions, parameters are pushed in reverse order of declaration right-to-left , so that the first parameter ends up at the lowest address and...

To change the value of an expression

2. Specify the expression in the Expression edit box. To modify a component property, specify the property name, for example, this. 3. Enter a value in the New Value edit box. The expression must evaluate to a result that is assignment-compatible with the variable you want to assign it to. Typically, if the assignment would cause a compile or runtime error, it is not a legal modification value. 4. Choose Modify. The new value is displayed in the Result box. You cannot undo a change to a...

To add a file open action to ActionManager

1. From the Additional page of the Tool palette, add an ActionManager component to the form. 2. Double-click ActionManager to display the Action Manager editor. Tip To display captions for nonvisual components such as ActionManager, choose Tools Environment Options. On the Designer tab, check Show component captions, and click OK. 3. If necessary, click the Actions tab. 4. Select New Standard Action from the drop-down list to display the Standard Action Classes dialog. 5. Scroll to the File...

Declaring a Custom Attribute Class

Creating a custom attribute is the same as declaring a class. The custom attribute class has a constructor, and properties to set and retrieve its state data. Custom attributes must inherit from TCustomAttribute. The following code declares a custom attribute with a constructor and two properties TCustomCodeAttribute class TCustomAttribute private Fpropl integer Fprop2 integer aVal integer procedure Setprop1 p1 integer procedure Setprop2 p2 integer public constructor Create const myVal integer...

Data Types 1

The following table shows commonly used data types, and how to translate them for managed code of Byte array a b of Bytearray a b of Byte When working with arrays and strings in structures, the MarshalAs attribute is used to describe additional information to the default marshaler about the data type. A record declared in Delphi 7, for example IntBuffer array 0 31 of Integer CharBuffer array 0 127 of Char lpszInput LPTSTR lpszOutput LPTSTR end Would be declared as follows in Delphi 8 for .NET...

To enable or disable a breakpoint or breakpoint group

1. Right-click the breakpoint icon in the Code Editor or in the Breakpoint List window and choose Enabled to toggle between enabled and disabled. 2. To enable or disable all breakpoints, right-click a blank area not on a breakpoint in the Breakpoint List window and choose Enable All or Disable All. 3. To enable or disable a breakpoint group, right-click a blank area not on a breakpoint in the Breakpoint List window and choose Enable Group or Disable Group. Disabling a breakpoint or breakpoint...

Scope

An identifier, such as a variable or function name, can be used only within the scope of its declaration. The location of a declaration determines its scope. An identifier declared within the declaration of a program, function, or procedure has a scope limited to the block in which it is declared. An identifier declared in the interface section of a unit has a scope that includes any other units or programs that use the unit where the declaration occurs. Identifiers with narrower scope,...

Reraising Exceptions

When the reserved word raise occurs in an exception block without an object reference following it, it raises whatever exception is handled by the block. This allows an exception handler to respond to an error in a limited way and then re-raise the exception. Re-raising is useful when a procedure or function has to clean up after an exception occurs but cannot fully handle the exception. For example, the GetFileList function allocates a TStringList object and fills it with file names matching a...

Dynamic Arrays

Dynamic arrays do not have a fixed size or length. Instead, memory for a dynamic array is reallocated when you assign a value to the array or pass it to the SetLength procedure. Dynamic-array types are denoted by constructions of the form declares a one-dimensional dynamic array of reals. The declaration does not allocate memory for MyFlexibleArray. To create the array in memory, call SetLength. For example, given the previous declaration, allocates an array of 20 reals, indexed 0 to 19....

To add code to the button Click event

1. Double-click the button to open the Code Editor. 2. In the button1_Click event code block, add the following code This closes the command to make sure that we will pass the parameter to the most current bdpSelectCommand. Self.BdpDataAdapter1.Active false This clears the data adapter so that we don't maintain old data textBoxl. This sets the parameter value to whatever value is in the text field. Self.BdpDataAdapterl.Active true This re-activates the data adapter so the refreshed data appears...

To add a parameter to the data adapter

1. Select the data adapter icon, then expand the properties under SelectCommand in the Fill area of the Object Inspector. You should be able to see your Select statement in the SelectCommand property drop down list box. 2. Change the ParameterCount property to 1. 3. Click the Collection entry next to the Parameters property. This displays the BdpParameter Collection Editor. 4. Click Add to add a new parameter. 5. Rename the parameter to emp. 6. Set BdpType to String, DbType to Object, Direction...

To create a data adapter and connection

1 Choose File New Application where Application is the language type you are using. 2. Click on the Data Explorer tab and drill down to find the IBConn1 connection under the Interbase node. 3. Drag and drop the EMPLOYEE table onto the Windows Form. This creates a BdpDataAdapter and BdpConnection and displays their icons in the Component Tray. 4. Select the data adapter icon, then click the Configure Data Adapter designer verb in the Designer Verb area at the bottom of the Object Inspector. This...

To configure an ECO Space using the designer

1. Select the UML packages containing the classes that you want to be persistent. 2. Choose a persistence method, either an RDBMS, or XML file. Here you will add the required persistence components to the ECO Space, and then configure the ECO Space to use the chosen persistence method by setting properties in the Object Inspector. 3. Validate the Model. This will cause the IDE to perform a number of checks to make sure the model is well-formed. For example, OCL expressions are checked to make...

The Relationship between VCLNET and the NET Framework

It's important to understand the relationship between VCL.NET and the .NET Framework. The .NET Framework provides a library of components, classes, and low-level functionality that supports a more transparent type of application development, particularly for Web applications. The concept of transparency, in this context, means that the framework manages much of the common functionality, from the display of buttons to remoting functionality, without regard to the underlying implementation...

Using Rave Reports ActiveX Components

You can drag-and-drop any ActiveX objects that are exposed by Rave Reports to your applications. The Delphi 8 for .NET tool palette provides a list of any available ActiveX objects. Just drag-and-drop the objects you want onto a Windows Form or a Web Form during design. Fill in the appropriate properties and modify any code in the Code Editor. You may need to reset your .NET components and to select the ActiveX components you want displayed, by selecting them from the Installed .NET Components...

To display child node contents in the XML file

1. In the Object Inspector with Button1 selected, double-click the OnClick event on the Events tab. The Code displays with the cursor in the TForml.Buttonlciick event handler block. 2. Enter the following code to display the stock price for the first child node when the Borland button is clicked Price BorlandStock.ChildNodes 'price' .Text Memol.Text Price 3. Add a var section just above the code block in the event handler, and enter the following local variable declarations BorlandStock...

To get a resource string from the Translation Repository

1. In the Translation Manager, click the Workspace tab. 2. Expand the project tree view to display the resource files that you want to edit. The .resx files are listed under the .NET Resources node. The .nfm files are listed under the Forms node. 3. Click the resource file you want to edit. The resource strings in the file are displayed in a grid in the right pane. 4- Right-click the field that you want to update and choose Repository Get strings from repository. If the Translation Repository...

For Statements

A for statement, unlike a repeat or while statement, requires you to specify explicitly the number of iterations you want the loop to go through. The syntax of a for statement is forcounter initialValuetofinalValuedostatement forcounter initialValuedowntofinalValuedostatement where counter is a local variable declared in the block containing the for statement of ordinal type, without any qualifiers. initialValue and finalValue are expressions that are assignment-compatible with counter....

To add multiple tables to one DataSet

1. From the Data Explorer, select a data source. 2. Drill down in the tree, then drag and drop the names of multiple tables, one at a time, onto your Windows Form or Web Form. This creates the BdpDataAdapter for each table and one BdpConnection for that data source and displays icons for those objects in the Component Tray. 3. Click the BdpDataAdapter icon named bdpDataAdapter1, by default to select it. 4. Click the Configure Data Adapter designer verb in the Designer Verb area at the bottom of...

Redistributing Delphi for NET Files

When building applications that use the VCL .NET framework, the way you build the application determines what files you need to distribute with it. If you build the application by compiling VCL for .NET units directly into the program executable file, the application will have external dependencies only on the .NET Framework. However, if you build the application by compiling the application to have external references to VCL for .NET assemblies, the application will have external dependencies...

To use the multiread exclusivewrite synchronizer

1. Create a global instance of TMultiReadExcllusiveWriteSynchronizer that is associated with the global memory you want to protect. 2. Before any thread reads from the memory, it must call BeginRead. 3. At the completion of reading memory, the thread must call EndRead. 4. Before any thread writes to the memory, it must call BeginWrite. 5. At the completion of writing to the memory, the thread must call EndWrite. Warning The multi-read exclusive-write synchronizer only works if every thread uses...

To Inspect a Windows Type Library

1 Select File Open from the menu. 2. In the Open dialog box, open the Files of type drop-down list, and Type Library. This will set the file filter to display files with extensions of .TLB, .OLB, .OCX, .DLL, and .EXE. 3. Navigate to the folder where the type library is located. Select the file and click Open. You can open multiple type libraries in the explorer. Each open type library is displayed in the tree in the left-pane the top-level node for a type library is denoted by the icon. To...

Setting Up the External Translation Manager

If you are localizing an application and do not have the Delphi 8 for .NET IDE, you can use the External Translation Manager ETM to perform the translations. The ETM provides the same basic functionality as the Translation Manager in the product. To use the ETM, the developer must provide you with the required ETM and project files. After you have finished the translations, you can send the translated files back to the developer to add to the project. The basic steps to set up the ETM are 1....

To create an association between two classes

1. Select Association as the type of element in the Tool Palette. 2. Move the mouse cursor over one of the classes to participate in the association. The class will be highlighted with a rectangle. 3. Click the mouse within the highlighted class and then move the mouse to the class at the other end of the association. 4. Again, the class will be highlighted with a rectangle. Click the mouse over the highlighted class. An association will be drawn between the two classes. Select the association,...

To set a dynamic property in the Object Inspector

1. In a form on the Design tab, click the object for which you want to set dynamic properties. 2. In the Object Inspector, expand DynamicProperties and click Advanced . If the object does not support dynamic properties, DynamicProperties is not displayed. Tip If the Object Inspector is arranged by category, DynamicProperties is displayed under Configurations. 3. Click the ellipsis button next to Advanced to display the Dynamic Properties dialog box. This dialog lists all of the properties that...

To import a model in XMI format

1. Export the model from the modeling tool, using the XMI format. When exporting from Rational Rose, choose XMI version 1.1, using the Unisys extension. 2- In Delphi 8 for .NET, start a new ECO application by selecting File New Other, and choosing ECO Application from the New Items dialog box. 3. Open the Model View Window, and right-click on the top-level project node in the tree. Choose Import Project from XMI. 4. In the XMI Import dialog box, click the Browse button to navigate to the XMI...

To wait for a task to complete

1. Create a TEvent object of global scope. 2. When a thread completes an operation other threads are waiting for, have the thread call TEvent. 3. To turn off the signal, call TEvent.ResetEvent. The following example is an OnTerminate event handler that uses a global counter in a critical section to keep track of the number of terminating threads. When Counter reaches 0, the handler calls the SetEvent method to signal that all processes have terminated procedure TDataModule.TaskTerminateThread...

Numeric Constants

Numeric constants must be integers, and their values must be between 2,147,483,648 and 4,294,967,295. By default, numeric constants use decimal notation, but the built-in assembler also supports binary, octal, and hexadecimal. Binary notation is selected by writing a B after the number, octal notation by writing an O after the number, and hexadecimal notation by writing an H after the number or a before the number. Numeric constants must start with one of the digits 0 through 9 or the...

To create a new package for the ActiveX button

1- Choose File New Other to create a new package. The New Items dialog displays. 2. Double-click Package on the New page to display the Package - package.dpk dialog and click Add. 3. On the Add unit tab of the Add dialog, browse to your project directory. 4. Select the ButtonXControll_TLB.pas file, and click Open. 5. Click OK to add the file to the package and return to the Package - package.dpk dialog. The Package - package.dpk dialog displays showing the files in the package and two required...

Configure Data Adapter

Delphi 8 for .NET provides a Configure Data Adapter designer which lets you configure SQL statements or stored procedures that are invoked to read or write to a database. Data Adapters are an integral part of the ADO.NET managed providers, which are a set of objects used to communicate between a data source and a dataset. Essentially, Adapters are used to exchange data between a data source and a dataset. This means reading data from a database into a dataset, and then writing changed data from...

Variant Arrays

You cannot assign an ordinary static array to a variant. Instead, create a variant array by calling either of the standard functions VarArrayCreate or VarArrayOf. For example, V VarArrayCreate 0,9 , varlnteger creates a variant array of integers of length 10 and assigns it to the variant v. The array can be indexed using v 0 , v 1 , and so forth, but it is not possible to pass a variant array element as a var parameter. Variant arrays are always indexed with integers. The second parameter in...

Advanced techniques 1

The use of a GCHandle, although relatively easy, is fairly expensive in terms of performance. It also has the possibility of resource leaks if handles aren't freed correctly. If object references are maintained in the managed code, it is possible to pass a unique index, for example the hash code returned by the GetHashCode method, to the unmanaged API instead of an object reference. A hash table can be maintained on the managed side to facilitate retrieving an object instance from a hash value...

To create an Active X library project for an ActiveX Active Form

1. Create a directory on your local drive for the ActiveX project. Give it an easy to find name, for example, ActiveX. 2. Create a second directory to contain the ActiveX component and an HTML file for deploying the Active Form to your Microsoft Internet Explorer Web browser. Name this directory ActiveX_Deploy. 3. Choose FileNewOther and select the ActiveX page in the New Items dialog. 4. On the ActiveX page, double-click Active Form. The Active Form Wizard displays. 5. Accept the default...

Building VCLNET Applications

VCL.NET gives you the capability to provide your Delphi VCL applications and components to Microsoft . NET Framework users. VCL.NET is an extended set of the VCL components that provide the means to quickly and easily build advanced applications in Delphi. Now, with Delphi 8 for .NET you get all of the benefits of the .NET Framework along with the ease-of-use and powerful component-driven application development you've come to expect from Delphi. Delphi 8 for .NET provides distinct application...

OleVariant

The OleVariant type exists on both the Windows and Linux platforms. The main difference between Variant and OleVariant is that Variant can contain data types that only the current application knows what to do with. OleVariant can only contain the data types defined as compatible with OLE Automation which means that the data types that can be passed between programs or across the network without worrying about whether the other end will know how to handle the data. When you assign a Variant that...

ADONET Application Deployment

When building database applications using Delphi 8 for .NET, copy the necessary files assemblies and DLLs for deployment to a specified location. The following table lists the name of the assemblies and DLLs and the location of where each assembly should reside. For specific database runtime assemblies, copy them to the following location For database DLLs, copy them to the following location