Moving to use of Delphi packages - best practice please?

I am trying to start making my own libraries avaialble as packages prior to compiling my Apps with these packages hence modularising my code. For years I've 'sort of' understood packages, breathing a sigh of relief when I load a component package and click on 'Install' and it does. I understand that the process of installing a component (or components) is via the creation of a BPL which is then registered with the IDE.

Where I begin to get lost is how to make files available so that I can compile with EITHER a package OR pre-compiled dcu's (like the third party vendors do) and without pointing my project at the source code all the time. I can create a package with the following settings:

Moving to use of Delphi packages - best practice please?

where I've specified that all my output will go into 'c:\scratch\wow'. After a build I find TEST.BPL, TEST.DCP and lots of DUC's. Now, when I point another project at this folder to use the DCU's, I get a missing DFM error (one of the units is a form). Should I be manually copying needed DFM's into this output folder? The DPK knows about this form, so why do I not get the DFM copied for me? I presume that using TEST.BPL, that file contains everything, but I wish to work in the two modes. Of course I can get around this by including the source folder in my project search path to find the DFM but third party libraries seem to already have the DFM's in their output folder. Did they install them there using the installer? Thanks


-------------Problems Reply------------

Yes, you should copy the .dfm to the directory with the compiled units (.dcus), if that is the only directory you want in your search path. The BPL will of course contain the .dfms, and you need a .dcp to be able to link a BPL with your app.

Third party tools must have put the .dfms together with the .dcus in the directory using their installer, indeed.

As others say you could use post-build events to copy your DFM files into place. Other people use a one-time external batch file that copies the DFMs to the DCU folder.

Personally I see very little benefit to making packages for things which are not developed also as reusable components. I also see very little benefit in partitioning an existing application into packages, when you don't reasonably need to use the same subsection or package more than once, or at designtime.

Things I would put into packages:

  1. Delphi visual and non-visual components.
  2. Things which absolutely must be plugged in at runtime, or left out. For example, supposing I sell MetaWare Light and MetaWare Pro, and instead of using compiler IFDEFs to build a differnt binary, I preferred for some reason to simply not ship the ADVANCEDFEATURE.BPL with my systems.

Things to beware of with packages:

  1. I have run into a lot of compiler bugs when combining packages with generics. I have also run into IDE crashes and lockups, in Delphi 2009, 2010, XE and XE2. (I believe XE3 is better)
  2. You should learn a bit about BorlandMM.dll and shared memory management in the BPL world before you move to it. There are some subtleties.
  3. Packages limits the ability of the linker to decide what to remove. In fact, it pretty much destroys it. Packages contain everything that is linked into them, and nothing publically accessible can be removed.
  4. Once you've created a binary package and shipped it to even one customer, you have a pretty difficult to modify contract (this BPL contains a particular signature or application binary interface) you have to be careful in the future to never change them, or mix and match them. Beware of DLL hell, even among your own customers, and be prepared to use versioning on your packages. Just as delphi packages have a version suffix, I recommend you use version suffixes in your own packages right off the bat, and bump them whenever binary compatibility has changed.
  5. Delphi handles build dependencies between packages about as well as could be hoped, which is less well than a single monolithic application. In applications that I have that make heavy use of packages, I find project groups that contain a bunch of packages that depend on each other are very difficult to manage and build quickly. In fact, I have experienced that both compiles and builds are slower and more frustrating than they would be in a singular 750Kline megaproject.

I really wonder if you're not that into the package area of Delphi (you breath a sigh of relief whenever a delphi component actually builds and installs without issue?) if you really want to move into the Packages World totally. By all means, you should experiment. But I wouldn't bet the farm on it yet. Learn some more first.

Instead of copying *.DFM manually you can use Post-Build Event (Project/Options/Build Event), ex:

copy “$(PROJECTDIR)\Unit1.DFM” “c:\Scratch\wow\Unit1.DFM”

I found a way to do this without moving .dfm files to the directory of .dcu files, so you can have a directory for .dcu files only one for .dcp files only and another for .bpl files only.

All you need to do is to create another directory on your good structure, as I do. The directory is called RES and in it should be placed all the resource files (.res files, not .dcr files) that are used by applications compiled using your packages (components). In the Delphi Library Path, you must include in addition to the DCU directory (you should already have) a directory named RES.

On your component (design time) do everything you want with the form (design it, put other components, etc). In the source code of the unit you replace {$R *.dfm} with {$R UnitName.dfm}. In doing so, save all and close the DPK. Now move the .dfm file (do not copy, move!) to the RES folder (the .dfm file is a resource file to the Delphi. The {$R} directive is proof!) and after that open the DPK again to understand what has changed.

First realize that you may not open the form (F12) from his unit, though no error was issued by Delphi about "DFM missing".

Now, do a Build on your package and then install it. Realized again? No errors displayed! This happened because you have indicated the location of .dfm file in the Delphi library search path (RES directory).

Done! You can use your component and dfm will be found when your component is included in an application.

Many of you can now say that this way I will not longer be able to visually edit a form in the component design time. Yes this is true, but if you think about it, why would I want to change so often a form into a component that, in practice, should only be used and slightly edited? Draw your own conclusions ;)

Category:delphi Views:1 Time:2011-07-24

Related post

  • C++ Builder DLL can not link unit obj from a Delphi Package (BPL). How to fix it? 2010-08-23

    I have a C++ Builder DLL that must link against a Delphi package (BPL), and I think it is possible that the Delphi package may need to be rebuilt to allow it to be used by both C++ Builder and Delphi, but I don't know which options need to be set on

  • delphi package automation installer into ide 2011-04-14

    Found a tool here long ago, and never had the time to test it. does anyone have a link to a tool that with it , you can automate the installation of packages into Delphi IDE? --------------Solutions------------- I found this : Delphi Package Installe

  • Python Daemon Packaging Best Practices 2009-02-26

    I have a tool which I have written in python and generally should be run as a daemon. What are the best practices for packaging this tool for distribution, particularly how should settings files and the daemon executable/script be handled? Relatedly

  • Delphi Package Build / Install debugging 2009-03-20

    I'm using Delphi 2007 Pro. I have a runtime package that includes a number of compound components I'm developing, which are based on TFrames. There is also a related design package which installs these components to the tool palette. These TFrame des

  • How to recognize the Registered classes in a Delphi Package 2009-06-12

    I am going through most of my applications and porting them to D2009 and I have one application that makes use of dynamic packages. For the life of me I cannot get my host application to recognize classes registered in a package. I traced through and

  • Delphi Package: "The following changes must be made-" never goes away 2009-06-26

    On one of my packages, which was adapted from another using Save-As and edit, I keep getting the following message (this is in Delphi 2007): ======= The following changes must be made before this package can be compiled. Choose OK to apply these chan

  • Is "implicitly imported" always a bad thing in Delphi packages? 2009-08-01

    Trying to rearrange my packages for a set of TFrame-descendent components, I'm finding it seemingly necessary to break out some of my utility TFrame descendents separate from the dialog forms which use them, mainly because the former are registered t

  • How to supress Entry Point Not Found error on loading Delphi package? 2010-07-28

    I maintain a program written in Delphi 6. It loads some bpl package files dynamically using SysUtils.LoadPackage. Often I change something in the program that causes a package to fail to load. When this happens a message box appears and then an excep

  • Moving From Delphi7 to Delphi XE or 2010 for Unicode? 2010-11-12

    ive a news server Built on Delphi7, using Indy9 TIdTCPServer, and the clients are using TClientSocket from ScktComp for size, and the traffic is encrypted in RC4 (string) what exactly do i need to make my app work on XE or 2010 with Unicode support?

  • Entities not mapped after moving them into external jar package 2011-05-17

    In my Java/Seam/JbossAS app, I decided to externalize my Model classes (hibernate entities) and moved them into another project. The project produces model.jar, which is then used by the main app. The model.jar dependency is resolved by Ivy. Building

  • Why are my jython "*$py.class" files not being updated with code changes after I moved them to a different package? 2011-08-24

    I originally had all of my modules in one package. I recently created a sub-package in the original package, and moved a few modules into that. My src folder, and the 2 package folders, are all in my PYTHONPATH. Since I relocated those modules, chang

  • Delphi package problem : Packaged units must refer only to packaged units.. (E2411) 2011-09-08

    The error I get is like this: [DCC Fatal Error] myunit3.pas(244): E2411 Unit XBAT in package B_Dsgn refers to unit QBEE which is not found in any package. Packaged units must refer only to packaged units I need to know what this error I am encounteri

  • Constants package best practice with heavily normalised database 2015-02-18

    I have a very normalised Oracle database. It has a number of large tables, along with maybe twenty or more very small tables (of < 10 records). For example, there is a table of statuses. To give an idea of the data within, it looks something like

  • How To Subclass A Form in Delphi? Best Practices? 2009-03-27

    I've got a base form in Delphi 2007 that I'd like to reuse in another project, adding some other buttons and such. I'm familiar with subclassing a non-GUI object, but it is possible to subclass a Form in the same fashion? Can you make changes to the

  • How to work around implicitly imported units in Delphi packages 2014-04-29

    I use GnuGetText to perform localization. This unit is used all over the place. So, when I create Package A, GnuGetText is implicitly imported in. And when I create Package B, GnuGetText is also implicitly imported in. The problem is that this unit c

  • What librairies exists to create "moving/living" UI in delphi? 2009-11-01

    While reading delphifeeds yesterday I discovered delQuery, which allows one to get some nice animation on his form very simply. I would like to know if there are any other libraries of that kind out there and what experience you had with them ? (I'm

  • Delphi thread best practices 2012-03-09

    I am implementing a synchronization method inside my application. The main steps it will perform are: Get XML content from a remote site Parse this XML using IXMLDomDocument2 Update a Firebird database The logic is quite complex, but it is working fi

  • Delphi Project Needing runtime Packages, even with runtime Packages off 2008-10-08

    My Delphi7 project will not run on my clients computer if i don't have a few of the runtime packages in the path. eg rtl70.bpl I have Build with runtime packages unticked, so shouldn't they be complied into the exe? Edit: the Project uses Jedi Packag

  • Delphi: Why does "use debug DCUs" become ineffective if I'm using packages in my project? 2008-11-03

    I'm building a project that uses the JVCL plugin system, which relies on Delphi packages, and ever since I added it to my project, debugging has become a nightmare because I'm no longer able to step-trace into the source of any VCL or RTL units. They

Copyright (C), All Rights Reserved.

processed in 0.105 (s). 11 q(s)