What project options to use for open source Delphi packages? - delphi

I've written some Delphi code I would like to share on GitHub. All code is contained in runtime and designtime packages as required. There are many "Project Options" to set for each project. (Output directories, search paths, compilation options, etc.) I've managed to find some default options that work well for my situation but reading other Q&As here it's clear there are multiple ways of working.
What project options should be used to allow the open source packages to easily be incorporated into individual projects?
I've recently started using NodeJS. The NPM package manager makes it super easy to use third-party packages in a project. Packages are installed with one simple command on the command line. Packages will automatically install any required dependencies.
PS: Feel free to edit this question if you would like to add extra things to consider.

Let's say you have this structure
MyComponent
Packages
DelphiXE7
Package2.dpr
source
bin
Delphi XE7
then set
Search Path
..\..\..\source
Unit output directory
..\..\..\bin\Delphi XE7\$(Platform)\$(Config)
After compilation for all supported platforms and both Release and Debug you will have this structure in the bin directory
MyComponent
Packages
DelphiXE7
Package2.dpr
source
bin
Delphi XE7
Android
Release
Debug
Win32
Release
Debug
Win64
Release
Debug
For installation you have to setup some path inside the IDE.
Environment
MYCOMPONENT => [root path to the files]
Library
Repeat that for all supported platforms
Library Path
$(MYCOMPONENT)\bin\Delphi XE7\$(Platform)\Release
Search Path
$(MYCOMPONENT)\source
Debug-DCU-Path
$(MYCOMPONENT)\bin\Delphi XE7\$(Platform)\Debug
If there are some language related units there is also a place to add (see Library - translated)
This ensures, that you have full debug feature (with Use Debug-DCU option set) and on release you have no debug code in your application.
Just a sidenote on libraries you should not want to install because you only use them in some projects.
Simply use the Optionset combined with a environment variable.
Here my SuperObject.optionset ($(USRLIB) points to a directory, where I collect all common used source code. And $(USRLIB)\ext is the place for all of the external libraries).
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DCC_UnitSearchPath>$(USRLIB)\ext\superobject;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType>OptionSet</Borland.ProjectType>
<BorlandProject>
<Delphi.Personality/>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
</Project>
To use the superobject library I simply add the optionset to the project (right mouse click on build configuration) and everything is fine.

Related

I get a Can't load package error although the BPL is there

This issue is driving me crazy. I'm trying to compile and install The QR Designer from QuickReports 6. I have an issue just with the one package. When I right the package in the IDE > Install the IDE gives me:
Can't load package C:\xe10_3\QRDesign\Win32\Debug\dclqrd_DXE10_3.bpl.
The specified module could not be found.
But the exact file is there.
I've also tried installing it via the menu under Components > Install Packages and then choosing the BPL from there, with the same issue.
I've tried to use Process Monitor as on this post here to find the issue:
Delphi Can't load package the specified module cannot be found
I couldn't fix the issue, but what I did pick up from Process Monitor was that some process was looking for the package here:
Computer\HKEY_CURRENT_USER\Software\Embarcadero\BDS\21.0\Package Cache\dclqrd_DXE10_3.bpl
That key didn't exists. I tried manually creating the key, but that didn't do a thing.
Any ideas?
UPDATE
Here is the list of packages:
As you can see, dclqrd_DXE10_3 is dependant on two others. Which I already built and installed. I removed its references and re-added them again now, to make sure the references are sound. I guess its like Remy said, the Specified module not found is probably not referring to dclqrd_DXE10_3 although I don't know what other module it could be referring to.
To install a package successfully in IDE, follow the steps:
Open the dpk/dproj/groupproj file in IDE
Build the package(s) for Windows 32-bit platform.
IDE itself is a 32-bit applicaton, so it should match.
Normally, it will build all dependent/required packages
Check if all chain of BPL & DCP files are generated in package Output directory.
It defaults to $(BDSCOMMONDIR)\Bpl & Dcp folders, but can be changed individually for each Package in Settings.
PBL packages are like DLL files. In order to load them, it requires all dependent BPLs.
If you have custom package output paths:
Check if your DCP output path is included in Tools\Options\Language\Delphi\Library Library Path for Windows 32-bit platform
Check if no duplicates of outdated compiled packages in default $(BDSCOMMONDIR)\Bpl & Dcp directories
Add the paths to library source pas files in Tools\Options\Language\Delphi\Library Browsing path or Library path
In some specific cases, if the package requires some extra dll-s like DB Client libraries, check if these dlls are 32-bit and are loadable, like included in %path% environement variable.
Note, some libraries offers package installer tools, that automagically do all mentioned things for you.
Also, there are universal package installer tools for quick working environement setup in one click.
I don't know why this fixed my issue, but it did.
The output directories for the bpl and dcp was set to be $(Platform)\$(Config)
The project files for the different packages exists in the same folder so the above config was supposed to be the debug folder or the release folder. Why only this package was thrown off I still don't know, but since changing the above packages to have a fixed path suddenly I could now install dclqrd_DXE10_3.bpl.
Thank you all for helping.

How can I Generate Setup Installation in Rad Studio?

What files must I add while building the installation file in Rad Studio using Advanced installer? When I chose the project file, I launched the file created with Advanced Installer, but it says that:
file_name.bpl missing
What should I do ?
If you don't build with runtime packages (Project->Options->Packages->Runtime packages->Link with runtime packages is False), then you only have to distribute your application executable (.exe).
If you build with runtime packages (Project->Options->Packages->Runtime packages->Link with runtime packages is True), you have to include those packages when you distribute your application executable (.exe). This requires at a minimum that you include the VCL and RTL packages (vclXXX.bpl and rtlXXX.bpl, where XXX depends on the specific version of RAD Studio that you're using).
Depending on what your application does, you may also have to include other runtime packages in your installer. You can find the list of packages that your application needs by looking at the runtime package list in Project->Options->Packages->Runtime Packages->Runtime packages (click the ... button to open the dialog).
For more information, see the RAD Studio documentation topic Deciding Which Runtime Packages to Use.
You should be able to find a list of names of the packages used from the menu at Project/Information for YourApplication This list should be available once the project has successfully compiled and linked.
Even more useful may be the Project/Deployment menu item. This item is designed to actually deploy your application and its files to a remote machine using paserver, and perhaps could be used to do that in the process of making your installation file.
However, the big advantage of Project/Deployment is that it lists not only the name of each file, but also the Directory where that file can be found.
It looks to me like there may be files under Project/Deployment, such as localization language files, that might not always be needed, so I would cross-check Project/Deployment (which shows the Directory) with the Project/Information for YourApplication list. However, Project/Deployment is where I would look to find the directory where the missing file_name.bpl that Advanced Installer needs can be found.

Installing Indy - which folders should be added to Delphi's Library list?

The directions on how to install Indy10 are (at least to me) a little vague in one place, and I'm hoping someone here can clarify a little.
The installation directions (From http://www.indyproject.org/sockets/Docs/Indy10Installation.en.aspx) state:
After Compiling
In your Indy directory you should now see some compiled .dcu files.
Open the IDE and go to the "Tools > Environment options > Select
Library" dialog tab. Now add the path to your files into the filepath
collection. Click Ok.
My Indy10 folder does not have any .dcu files in the root folder. It does have a bunch of DCU files in C:\code\Indy10\Output\DCU\Win32\Debug ... does this mean I should be adding C:\code\Indy10\Output\DCU\Win32\Debug to my library path? (And for that matter, should I be building Indy in Debug or Release mode, or does it matter?) Are there any other subfolders I need to add to the library path? Indy 10 has a much more complex folder structure than Indy 9 and I'm not convinced I've configured things "correctly".
Nearly every component package I install I touch the project options for the runtime package(s) to get a clean install.
Project Options
General Configuration
Output directory {componentpath}\lib\XE4\$(platform)\$(config)
Release Configuration
Output directory {componentpath}\lib\XE4\$(platform)
After that I compile the whole package for all target platforms in release and debug mode. Using a Build-Group is very useful to do that.
Now it is time to add the library paths (for each platform)
Library path {componentpath}\lib\XE4\$(platform)
Debug DCU path {componentpath}\lib\XE4\$(platform)\debug
Browse path all directories containing the source
In your own projects you can control which .dcu versions are used by setting the Use Debug-DCU option.

How not to compile installed packages everytime anew with the Application that uses it?

When I install a package in the IDE and use it in a project, it gets recompiled (DCUs are replaced) everytime I compile my project.
I can't imagine that this is intended - the RTL and VCL are not compiled each time either, are they?
I have played a bit with the paths in Tools > Options > Environment Options > Delphi Options > Library, but without success.
I have found a construction allowing compilation of my project without recompiling the package having DCUs and PASs in diffenent paths, but in this construction Delphi is not able to locate the sources at all from the Code Editor (SHIFT-clicking for example), so this is not an option.
To avoid recompilation you have to have separate folders for .dcu files and .pas files.
Usually this is done by settings the output dir in a package contained in the library. You build the package and it will produce the .dcu files in a output folder that is different from the source folder.
To use the package you then:
have to point the library path to the output folder (with the compiled .dcu files).
can optionally point the search path to the source folder (with the .pas files).
This gets a little more complicated when you have .dfm files in the package as well.
Every .pas file that the compiler sees in the library path is recompiled. (Actually only the last instance, because you can have the same unit in different directories that are listed in the library path).
To enable IDE features like CTRL-click you have to set the {$Y+} compiler switch in your package which can be done in the IDE Compiling options:
http://docwiki.embarcadero.com/RADStudio/XE4/en/Compiling#Debugging_Options

How split a Delphi solution into reusable run-time packages?

I'm starting with Delphi XE5 and I would like to split my application in one exe and multiple reusable libraries. That means I don't want to split the running *.exe application in DLLs or runtime Packages.
To achieve this, I have seen that in delphi we can create runtime packages and I followed the following steps:
I have created a new VCL Forms Application project (EXE project).
I have added a new Package project (BPL project) to the project group and I have modified its project options to set usage options to 'Runtime only' and build control to 'Explicit rebuild'.
I have added a dependency betwen the EXE project and the BPL project (EXE project depends on BPL project).
Finally I have compiled the BPL project and added the generated DCP file as a runtime package in the EXE project (Project options/Package/Runtime Packages).
But when I add a reference on the EXE project to use a module (moduleX for example) from the BPL project, compiler give me an error like this:
[dcc32 Fatal Error] ModuleX.pas(7): F1026 File not found: 'C:\DDDProject\MyEXEProject\ModuleX.dcu'
If I mark as checked the 'Link with runtime packages' option in the EXE project (MyEXEProject) the solution compiles without errors but I can't run or debug the application.
Please, can anyone help me?
I don't want to split the running *.exe application in DLLs or runtime Packages.
Runtime Package BPL files are DLLs. That is what allows them to be shared amongst multiple EXEs. They are just normal DLLs with special VCL/FMX handling built in.
When you enable the "Link with runtime packages" option, you are linking the EXE file to your BPL file (or DYLIB or SO file, if compiling for platforms other than Windows), so you MUST distribute the BPL file (and any other BPL files it depends on, like rtl190.bpl and vcl190.bpl) with your EXE file. So they have to be in the EXE's folder, or at least in the OS search path, in order for the EXE to run.
When you disable the "Link with runtime packages" option, your package's code is statically linked directly into the EXE file, so you need to make sure the EXE project's search paths include the folder were your package's DCU file(s) are located.
If you want to create a reusable library but not a BPL, then create a Static Library (a LIB file) instead of a Runtime Package. You can then add the LIB file to multiple projects as needed.

Resources