|
INPRISE Online And ZD Journals Present:
As we mentioned in the April article "Whats New in C++Builder 3," C++Builder 3 includes support for packages, which contain code for C++Builder components. When you get right down to it, a package is just a DLL with the extension BPL. C++Builder uses two types of packages: runtime packages and design packages. Lets take a moment to discuss how components worked in C++Builder 1. Then well contrast that with packages and examine how both types of package fit into C++Builder 3. Components in C++Builder 1 With that bit of history behind us, lets move on to how C++Builder 3 uses packages. Well begin with runtime packages. Runtime packages When you create an application, you can choose whether to use runtime packages. If you build your application without using runtime packages, its created essentially the same as it would have been in C++Builder 1. If you use runtime packages, however, none of the code for the components is contained in your applications EXE file. Instead, the code is pulled from the runtime packages at runtime as needed. This is the traditional EXE/DLL relationship. To enable runtime packages, open the Project Options dialog box and select the Packages page. Select the Use Runtime Packages check box, and C++Builder will build your application so that it uses runtime packages.
Using runtime packages has advantages and disadvantages. One advantage is that all your applications and DLLs use a common code base (the packages). This commonality eliminates code duplication in every EXE or DLL. As a result, EXEs and DLLs that use runtime packages are smaller. However, this isnt always a good thing, as youll see next. The disadvantage to using runtime packages is that you have to ship them with your application. The runtime packages are relatively large, so you must consider the size of your EXE with and without packages to determine whether youre saving anything. For example, lets say your application built without runtime packages is 500KB. The size of the application using runtime packages might be as little as 75KBbut VCL30.BPL itself is 1.4MB, so using runtime packages wouldnt make much sense in that case. However, if you have an application and DLLs that total 10MB, you can probably benefit from runtime packages. Another disadvantage of using runtime packages is the extra work involved in deploying your application. Lets look at deployment issues in more detail. Deploying an application using
packages Use care when you deploy an application that uses runtime packages. The C++Builder license agreement states that you cant alter the VCL packages, and this stipulation helps avoid the problem of mismatched packages (packages having the same name but containing different code). You should use a proven installation program when you deploy applications that use runtime packages. If a package youre installing already exists on a users system, the installation program will check the version numbers to ensure that the version being installed isnt older than the existing version.
Design packages You can use a single package as both a runtime and a design package, but proper implementation dictates that no unnecessary code is contained in the runtime package. For example, theres no reason to include a lot of code and resources (forms) for component editors and property editors in the runtime package, because that code is needed only at design time. If you have a simple component with no property editors, then you can probably get by with a single package that acts as both a design package and a runtime package. A good component library, though, will probably have both design and runtime packages to minimize the size of the runtime package. You must use a design package to install components on the component palette. Almost all commercial component vendors provide design packages with their component libraries. Sometimes, however, youll run across a component that doesnt contain a design package. You can still install these components, because C++Builder contains a default design package for any components that dont have their own. Remember, design packages are only for the C++Builder IDEs usedont ship them with your applications. Installing design packages Notice that theres no rebuilding of the component palette, as there was in C++Builder 1. The C++Builder 3 IDE simply has to load the design packages that are already built (remember, theyre really just DLLs) and update the component palette tabs. You can use most packages created for Delphi 3 in C++Builder, but youll probably need to rebuild them using the DCC32.EXE that comes with C++Builder. If you have the package source files, you can build the packages from the command line. If you dont have the package source files, then you should contact the component vendor and ask for a package compatible with C++Builder. You can remove a design package from the component palette in one of two ways. One way is to remove the component completely. To do so, select the component in the Design Packages list box (on the Packages page of the Project Options dialog box) and click the Remove button. The package will be removed from the list and from the component palette. The other way to remove a design package is to leave it in the list of installed packages but clear the check box next to its name. Doing so temporarily removes the package from the component palette but leaves the component in the list of installed components in case you want to add it again later.
Conclusion Kent Reisdorph is a senior software engineer at TurboPower Software and a member of TeamB, Borland's volunteer online support group. He's the author of Teach Yourself C++Builder in 21 Days and Teach Yourself C++Builder in 14 Days. You can contact Kent at kentr@turbopower.com. Back to Top Back to 1998 Index of Articles Copyright © 1998, Ziff-Davis Inc. All rights reserved. ZD Journals and the ZD Journals logo are trademarks of Ziff-Davis Inc. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis is prohibited. |