Delphi 2007 Install Component



All components are installed in the IDE as packages. If you've written your own components, create and compile a package that contains them. (See 'Creating and editing packages' on page 16-7.) Your component source code must follow the model described in the Component Writer's Guide.

  1. Delphi Components Download
  2. Tms Delphi Components

To install or uninstall your own components, or components from a third-party vendor, follow these steps:

I'm writing a package in Delphi 2007 containing a component and several classes. I want to 'install' the classes as well as the components. To be more precise: when a component is installed, the unit is somehow registered such that it is not necessary to add its path to the search path in the project.

In this lesson, we are going to install a custom component into Delphi. Thank You Wayne Barron CFF Coding Source https://twitter.com/Cod. Install Komponen Comport Library delphi 7. The TClientSocket and TServerSocket components are available in BDS 2006 and Delphi 2007, however, they are by default, not installed. In order to install, from the menu, select Component, Install Packages. In the Install Packages dialog, click on Add. Delphi 1-7 Use the Components - Install Component menu entry to install the component into the default dclusr-Package.

1 If you are installing a new package, copy or move the package files to a local directory. If the package is shipped with .bpl, .dcp, and .dcu files, be sure to copy all of them. (For information about these files, see 'Packages and standard DLLs.')

The directory where you store the .dcp file—and the .dcu files, if they are included with the distribution—must be in the Delphi Library Path.

If the package is shipped as a .dpc (package collection) file, only the one file needs to be copied; the .dpc file contains the other files. (For more information about package collection files, see 'Package collection files' on page 16-14.)

2 Choose Component!Install Packages from the IDE menu, or choose Project! Options and click the Packages tab. A list of available packages appears in the Design packages list box.

  • To install a package in the IDE, select the check box next to it.
  • To uninstall a package, uncheck its check box.
  • To see a list of components included in an installed package, select the package and click Components.
  • To add a package to the list, click Add and browse in the Add Design Package dialog for the directory where the .bpl file resides (see step 1). Select the .bpl or .dpc file and click Open. If you select a .dpc file, a new dialog box appears to handle the extraction of the .bpl and other files from the package collection.
  • To remove a package from the list, select the package and click Remove.

3 Click OK.

The components in the package are installed on the Component palette pages specified in the components' RegisterComponents procedure, with the names they were assigned in the same procedure.

New projects are created with all available packages installed, unless you change the default settings. To make the current installation choices into the automatic default for new projects, check the Default check box at the bottom of the Packages tab of the Project Options dialog box.

To remove components from the Component palette without uninstalling a package, select Component! Configure Palette, or select Tools ! Environment Options and click the Palette tab. The Palette options tab lists each installed component along with the name of the Component palette page where it appears. Selecting any component and clicking Hide removes the component from the palette.

Creating and editing packages

Creating a package involves specifying:

  • A name for the package.
  • A list of other packages to be required by, or linked to, the new package.
  • A list of unit files to be contained by, or bound into, the package when it is compiled. The package is essentially a wrapper for these source-code units. The Contains clause is where you put the source-code units for custom components that you want to compile into a package.

The Package editor generates a package source file (.dpk).

Creating a package

To create a package, follow the procedure below. Refer to 'Understanding the structure of a package' on page 16-8 for more information about the steps outlined here.

1 Choose File I New I Other, select the Package icon, and click OK. The generated package appears in the Package editor. The Package editor displays a Requires node and a Contains node for the new package.

2 To add a unit to the contains clause, click the Package editor's Add button. In the Add Unit page, type a .pas file name in the Unit file name edit box, or click Browse to browse for the file, and then click OK. The unit you've selected appears under the Contains node in the Package editor. You can add additional units by repeating this step.

3 To add a package to the requires clause, click the Add button. In the Requires page, type a .dcp file name in the Package name edit box, or click Browse to browse for the file, and then click OK.The package you've selected appears under the Requires node in the Package editor. You can add additional packages by repeating this step.

4 Click the Options button, and decide what kind of package you want to build.

  • To create a design-time only package (a package that cannot be used at runtime), check the Designtime only radio button. (Or add the {$DESIGNONLY} compiler directive to your dpk file.)
  • To create a runtime-only package (a package that cannot be installed), select the Runtime only radio button. (Or add the {$RUNONLY} compiler directive to the dpk file.)
  • To create a package that is available at both design time and runtime, select the Designtime and runtime radio button.

5 In the Package editor, click the Compile button to compile your package. Note You can also click the Install button to force a make.

Do not use IFDEFs in a package file (.dpk) when writing cross-platform applications. You can use them in the source code, however.

Editing an existing package

You can open an existing package for editing in several ways:

  • Choose File I Open (or Filel Reopen) and select a dpk file.
  • Choose Componentl Install Packages, select a package from the Design packages list, and click the Edit button.
  • When the Package editor is open, select one of the packages in the Requires node, right-click, and choose Open.

To edit a package's description or set usage options, click the Options button in the Package editor and select the Description tab.

The Project Options dialog has a Default check box in the lower left corner. If you click OK when this box is checked, the options you've chosen are saved as default settings for new projects. To restore the original defaults, delete or rename the defproj.dof file.

Understanding the structure of a package

Packages include the following parts:

  • Package name
  • Requires clause
  • Contains clause

Naming packages

Package names must be unique within a project. If you name a package Stats, the Package editor generates a source file for it called Stats.dpk; the compiler generates an executable and a binary image called Stats.bpl and Stats.dcp, respectively. Use Stats to refer to the package in the requires clause of another package, or when using the package in an application.

Delphi

You can also add a prefix, suffix, and version number to your package name. While the Package editor is open, click the Options button. On the Description page of the Project Options dialog box, enter text or a value for LIB Suffix, LIB Prefix, or LIB Version. For example, to add a version number to your package project, enter 7 after LIB Version so that Packagel generates Packagel .bpl.7.

Requires clause

The requires clause specifies other, external packages that are used by the current package. An external package included in the requires clause is automatically linked at compile time into any application that uses both the current package and one of the units contained in the external package.

If the unit files contained in your package make references to other packaged units, the other packages should appear in your package's requires clause or you should add them. If the other packages are omitted from the requires clause, the compiler will import them into your package 'implicitly contained units.'

Note Most packages that you create require rtl. If using VCL components, you'll also need to include the vcl package. If using CLX components for cross-platform programming, you need to include VisualCLX.

Avoiding circular package references

Packages cannot contain circular references in their requires clause. This means that:

  • A package cannot reference itself in its own requires clause.
  • A chain of references must terminate without rereferencing any package in the chain. If package A requires package B, then package B cannot require package A; if package A requires package B and package B requires package C, then package C cannot require package A.

Handling duplicate package references

Duplicate references in a package's requires clause—or in the Runtime Packages edit box—are ignored by the compiler. For programming clarity and readability, however, you should catch and remove duplicate package references.

Contains clause

The contains clause identifies the unit files to be bound into the package. If you are writing your own package, put your source code in pas files and include them in the contains clause.

Avoiding redundant source code uses

A package cannot appear in the contains clause of another package.

All units included directly in a package's contains clause, or included indirectly in any of those units, are bound into the package at compile time.

A unit cannot be contained (directly or indirectly) in more than one package used by the same application, including the IDE. This means that if you create a package that contains one of the units in vcl you won't be able to install your package in the IDE. To use an already-packaged unit file in another package, put the first package in the second package's requires clause.

Editing package source files manually

Package source files, like project files, are generated by Delphi from information you supply. Like project files, they can also be edited manually. A package source file should be saved with the .dpk (Delphi package) extension to avoid confusion with other files containing Del source code.

To open a package source file in the Code editor,

1 Open the package in the Package editor.

2 Right-click in the Package editor and select View Source.

  • The package heading specifies the name for the package.
  • The requires clause lists other, external packages used by the current package. If a package does not contain any units that use units in another package, then it doesn't need a requires clause.
  • The contains clause identifies the unit files to be compiled and bound into the package. All units used by contained units which do not exist in required packages will also be bound into the package, although they won't be listed in the contains clause (the compiler will give a warning).

For example, the following code declares the vcldb package (in the source file vcldb70.bpl):

¡{compiler directives omitted} requires rtl, vcl;

contains

NewComponentl in 'NewComponentl.pas';

end.

Compiling packages

You can compile a package from the IDE or from the command line. To recompile a package by itself from the IDE:

1 Choose File ! Open and select a package (.dpk).

2 Click Open.

3 When the Package editor opens:

  • Click the Package editor's Compile button.
  • In the IDE, choose Project! Build.

Note You can also choose FilelNew ¡Other and double-click the Package icon. Click the Install button to make the package project. Right-click the package project nodes for options to install, compile, or build.

You can insert compiler directives into your package source code. For more information, see 'Package-specific compiler directives' below.

If you compile from the command line, you can use several package-specific switches. For more information, see 'Compiling and linking from the command line' on page 16-13.

Package-specific compiler directives

The following table lists package-specific compiler directives that you can insert into your source code.

Table 16.2 Package-specific compiler directives Directive Purpose

{$IMPLICITBUILD OFF} Prevents a package from being implicitly recompiled later.

Use in .dpk files when compiling packages that provide low-level functionality, that change infrequently between builds, or whose source code will not be distributed.

  • G-} or {IMPORTEDDATA OFF} Disables creation of imported data references. This directive increases memory-access efficiency, but prevents the unit where it occurs from referencing variables in other packages.
  • WEAKPACKAGEUNIT ON} Packages unit 'weakly.' See 'Weak packaging' on page 16-12 below.
  • DENYPACKAGEUNIT ON} Prevents unit from being placed in a package.
  • DESIGNONLY ON}Compiles the package for installation in the IDE. (Put in .dpk file.)
  • RUNONLY ON}Compiles the package as runtime only. (Put in .dpk file.)

Note Including {$DENYPACKAGEUNIT ON} in your source code prevents the unit file from being packaged. Including {$G-} or {$IMPORTEDDATA OFF} may prevent a package from being used in the same application with other packages. Packages compiled with the {$DESIGNONLY ON} directive should not ordinarily be used in applications, since they contain extra code required by the IDE. Other compiler directives may be included, if appropriate, in package source code. See Compiler directives in the online Help for information on compiler directives not discussed here.

See Chapter 9, 'Libraries and packages,' in the Delphi Language Guide for more information on package-specific compiler directives.

Refer to 'Creating packages and DLLs' on page 8-11 for additional directives that can be used in all libraries.

Weak packaging

The $WEAKPACKAGEUNITdirective affects the way a .dcu file is stored in a package's .dcp and .bpl files. (For information about files generated by the compiler, see 'Package files created when compiling' on page 16-13.) If {$WEAKPACKAGEUNIT ON} appears in a unit file, the compiler omits the unit from bpls when possible, and creates a non-packaged local copy of the unit when it is required by another application or package. A unit compiled with this directive is said to be weakly packaged.

For example, suppose you've created a package called pack1 that contains only one unit, unit1. Suppose unit1 does not use any additional units, but it makes calls to rare.dll. If you put the {$WEAKPACKAGEUNIT ON} directive in unit1.pas (Delphi) or unit1.cpp (C++) when you compile your package, unit1 will not be included in pack1.bpl; you will not have to distribute copies of rare.dll with pack1. However, unit1 will still be included in pack1.dcp. If unit1 is referenced by another package or application that uses pack1, it will be copied from pack1.dcp and compiled directly into the project.

Now suppose you add a second unit, unit2, to pack1. Suppose that unit2 uses unit1. This time, even if you compile pack1 with {$WEAKPACKAGEUNIT ON} in unit1.pas, the compiler will include unit1 in pack1.bpl. But other packages or applications that reference unit1 will use the (non-packaged) copy taken from pack1.dcp.

Note Unit files containing the {$WEAKPACKAGEUNIT ON} directive must not have global variables, initialization sections, or finalization sections.

The {$WEAKPACKAGEUNIT ON} directive is an advanced feature intended for developers who distribute their packages to other programmers. It can help you to avoid distribution of infrequently used DLLs, and to eliminate conflicts among packages that may depend on the same external library.

For example, the PenWin unit references PenWin.dll. Most projects don't use PenWin, and most computers don't have PenWin.dll installed on them. For this reason, the PenWin unit is weakly packaged in vcl. When you compile a project that uses PenWin and the vcl package, PenWin is copied from vcl70.dcp and bound directly into your project; the resulting executable is statically linked to PenWin.dll.

If PenWin were not weakly packaged, two problems would arise. First, vcl itself would be statically linked to PenWin.dll, and so you could not load it on any computer which didn't have PenWin.dll installed. Second, if you tried to create a package that contained PenWin, a compiler error would result because the PenWin unit would be contained in both vcl and your package. Thus, without weak packaging, PenWin could not be included in standard distributions of vcl.

Compiling and linking from the command line

When you compile from the command line, you can use the package-specific switches listed in the following table.

Table 16.3 Package-specific command-line compiler switches

Switch Purpose

  • G-Disables creation of imported data references. Using this switch increases memory-access efficiency, but prevents packages compiled with it from referencing variables in other packages.
  • LEpathSpecifies the directory where the package file (.bpl) will be placed.
  • LNpathSpecifies the directory where the package file (.dcp) will be placed.
  • LUpackage Use packages.
  • ZPrevents a package from being implicitly recompiled later. Use when compiling packages that provide low-level functionality, that change infrequently between builds, or whose source code will not be distributed.

Note Using the -$G- switch may prevent a package from being used in the same application with other packages. Other command-line options may be used, if appropriate, when compiling packages. See 'The Command-line compiler' in the online Help for information on command-line options not discussed here.

Package files created when compiling

To create a package, you compile a source file that has a .dpk extension. The base name of the .dpk file becomes the base name of the files generated by the compiler. For example, if you compile a package source file called traypak.dpk, the compiler creates a package called traypak.bpl.

A successfully compiled package includes .dcp, .dcu and bpl files. For a detailed description of these files, see 'Packages and standard DLLs' on page 16-2.

These files are generated by default in the directories specified in Library page of the Tools!Environment Options dialog. You can override the default settings by clicking the Options button in the Package editor to display the Project Options dialog; make any changes on the Directories/Conditionals page.

Deploying packages

Deploying packages

You deploy packages much like you deploy other applications. The files you distribute with a deployed package may vary. The bpl and any packages or dlls required by the bpl must be distributed.

For general deployment information, refer to Chapter 18, 'Deploying applications.'

Deploying applications that use packages

When distributing an application that uses runtime packages, make sure that your users have the application's .exe file as well as all the library (.bpl or .dll) files that the application calls. If the library files are in a different directory from the .exe file, they must be accessible through the user's Path. You may want to follow the convention of putting library files in the WindowsSystem directory. If you use InstallShield Express, your installation script can check the user's system for any packages it requires before blindly reinstalling them.

Distributing packages to other developers

If you distribute runtime or design-time packages to other Delphi developers, be sure to supply both .dcp and .bpl files. You will probably want to include .dcu files as well.

Package collection files

Package collections (.dpc files) offer a convenient way to distribute packages to other developers. Each package collection contains one or more packages, including bpls and any additional files you want to distribute with them. When a package collection is selected for IDE installation, its constituent files are automatically extracted from their .pce container; the Installation dialog box offers a choice of installing all packages in the collection or installing packages selectively.

To create a package collection:

1 Choose Tools ! Package Collection Editor to open the Package Collection editor.

2 Either choose Edit!Add Package or click the Add a package button, then select a bpl in the Select Package dialog and click Open. To add more bpls to the collection, click the Add a package button again. A tree diagram on the left side of the Package editor displays the bpls as you add them. To remove a package, select it and either choose Edit! Remove Package or click the Remove the selected package button.

3 Select the Collection node at the top of the tree diagram. On the right side of the Package Collection editor, two fields appear:

  • In the Author/Vendor Name edit box, you can enter optional information about your package collection that appear in the Installation dialog when users install packages.
  • Under Directory list, list the default directories where you want the files in your package collection to be installed. Use the Add, Edit, and Delete buttons to edit this list. For example, suppose you want all source code files to be copied to the same directory. In this case, you might enter Source as a Directory name with C: MyPackageSource as the Suggested path. The Installation dialog box will display C:MyPackageSource as the suggested path for the directory.

4 In addition to bpls, your package collection can contain .dcp, .dcu, and .pas (unit) files, documentation, and any other files you want to include with the distribution. Ancillary files are placed in file groups associated with specific packages (bpls); the files in a group are installed only when their associated bpl is installed. To place ancillary files in your package collection, select a bpl in the tree diagram and click the Add a file group button; type a name for the file group. Add more file groups, if desired, in the same way. When you select a file group, new fields will appear on the right in the Package Collection editor.

  • In the Install Directory list box, select the directory where you want files in this group to be installed. The drop-down list includes the directories you entered under Directory list in step 3, above.
  • Check the Optional Group check box if you want installation of the files in this group to be optional.
  • Under Include Files, list the files you want to include in this group. Use the Add, Delete, and Auto buttons to edit the list. The Auto button allows you to select all files with specified extensions that are listed in the contains clause of the package; the Package Collection editor uses the global Library Path to search for these files.

5 You can select installation directories for the packages listed in the requires clause of any package in your collection. When you select a bpl in the tree diagram, four new fields appear on the right side of the Package Collection editor:

  • In the Required Executables list box, select the directory where you want the .bpl files for packages listed in the requires clause to be installed. (The dropdown list includes the directories you entered under Directory list in step 3, above.) The Package Collection editor searches for these files using Delphi's global Library Path and lists them under Required Executable Files.
  • In the Required Libraries list box, select the directory where you want the .dcp files for packages listed in the requires clause to be installed. (The drop-down list includes the directories you entered under Directory List in step 3, above.) The Package Collection editor searches for these files using the global Library Path and lists them under Required Library Files.

6 To save your package collection source file, choose File!Save. Package collection source files should be saved with the .pce extension.

7 To build your package collection, click the Compile button. The Package Collection editor generates a .dpc file with the same name as your source (.pce) file. If you have not yet saved the source file, the editor queries you for a file name before compiling.

To edit or recompile an existing .pce file, select File!Open in the Package Collection editor and locate the file you want to work with.

Was this article helpful?

Delphi 7 has a main menu option for Component|Install Component that guides you through the process of getting a component onto the Palette. Unfortunately, that functionality was lost in the IDE’s transformation to the Borland Developer Studio. I won’t go into details but I was not happy to say the least when I learned of this change.

Regardless, your choices of installing components hasn’t changed it’s just you’re no longer guided through the process. I thought it might be useful to walk through a few scenarios using Delphi 2007. There are many ways to accomplish these tasks so don’t consider this your only option.

Creating and installing a new component into a new Package
Here are the steps necessary to create a new component and get it installed onto the palette though refer to the section below on the caveat with the New VCL Component wizard:

  1. Start the IDE
  2. Select File|New|Package
  3. Select File|Save As and give your package the desired name
  4. Select View|Project Manager
  5. Right click the package node and select Options then be sure to fill in the Description for this package as it will be used in the Install Packages dialog
  6. Select Component|New VCL Component… which will display the New VCL Component Wizard (see note below)
  7. Select TButton as the ancestor and click Next
  8. Leave the defaults for Classname etc. and click Next
  9. Select “Add unit to Package1.bdsproj project”
  10. Select View|Project Manager and right click Package1 and select Install

That will get you a new design time package with a new component installed and on your palette. If you have an existing .PAS file that contains a component(s) all you need to do is right click the Contains node under your package and select “Add…”.

Installing an existing component into a new package
The steps here are pretty much the same as above except at step 4 instead of starting the New VCL Component wizard simply open the .PAS file that contains the component(s) and add it to the Contains node of your package.

Installing components into an existing package
In this case, you’ve already created and installed a design time package and you’d like to add a new component.

  1. Select Component|Install Packages (Sure, this may seem a bit odd since the package we want is already installed)
  2. Find the desired package and select it in the Design Packages listbox
  3. Click the Edit button which will prompt you to cancel the dialog and open the package as a project
  4. Select View|Project Manager
  5. Expand the package node and right click the Contains node under the package and select “Add…” and add your existing .PAS file or select Component|New VCL Component and follow the steps above
  6. Right click the package node in the Project Manager and select Compile which will rebuild and reinstall your design time package

Installing existing design time packages
If you have existing component packages and you want to get them on the palette:

  1. Select Component|Install Packages
  2. Click the Add button and multi-select the design time packages you want to install then click Ok. You don’t really have to worry too much if the package you select is design time or runtime as the IDE will let you know if there is an issue installing the package.

The issue with the New VCL Component Wizard
There is one rather major flaw with the New VCL Component Wizard and that’s that it places both design-time and runtime code into a single unit. The runtime code is the code that implements the component itself. The design-time code is the Register procedure with the call to RegisterComponents which should be removed and placed in a different unit which belongs it a design time package. In the first scenario above it would be wise to create a second, design-time only package and split the code as described. Additionally, you should mark your packages explicitly as design-time and runtime using Usage Options from the Project Options dialog.

Mixing design-time and runtime code in a single package is a bad idea and needs to be avoided. Design-time code isn’t necessary at runtime and typically contains property and/or component editors along with various registration calls which are only meaningful when the package is installed in the IDE.

Delphi Components Download

Let me know if this was helpful and if you’ve been impacted by the removal of Component|Install Component functionality. I’ve already discussed it with Nick Hodges.

Tms Delphi Components

[UPDATE: May 9, 2007] Also see Creating Packages from the Delphi wiki.