Component Design - "File not found: 'DockForm.dcu"? - delphi

I am writing a component that requires the use of both the units
DesignIntf, DesignEditors
When i build my package, i get the error
File not found: 'DockForm.dcu'
When I add "designide.dcp" to the "requires" section of the package, it builds and compiles just fine.
HOWEVER, when i add the component to a new project (in design time, it works. I can change all the properties, etc......BUT, it does NOT work in runtime. When i run the application with the component on the main form, i once again get the "
"File not found: 'DockForm.dcu'" error
please help
thanks

You're not allowed to use any of the Design* units in your runtime code. It's for use at designtime in the IDE only, and can't be linked in to your own application. That's why the .DCUs aren't found; they're not provided, and their functionality is provided in the designtime only packages in the IDE itself.

Related

Delphi 10.x "Cannot resolve unit name" for newly installed library

I encountered the following puzzling situation while installing a third-party library, in this case Virtual Treeview, which I will use as an example herein.
After following the installation procedure from INSTALL.txt, the new components appeared in Delphi's component palette, and can be added to a form.
However, building one of the supplied example projects, in this case "Minimal" fails, saying:
'Cannot resolve unit name "VirtualTrees" at line xxx', which is the uses statement in which VirtualTrees is listed.
Congruent with that symptom, in the source code editor, (uses) VirtualTrees, and subsidiary component declarations, were marked with red squiggles, indicating identifier undeclared or not resolved.
The supplied demo project was set to target Windows 32. But puzzlingly, if I switch the target to Windows 64, it will compile.
Installation consisted of:
Unzip the supplied zip file to wherever you locate source packages.
In Delphi, open the project group: File > Open .... VirtualTreeView.groupproj
Once loaded, in the project tree, right click on VirtualTreesD26.bpl > Install.
Add VirtualTreeView's "Source" folder to the Library Path, using
"Tools > Options > Language > Delphi Options > Library > Library Path > [...]"
What's allowing the IDE to know about the component, but then failure to compile for Windows 32, yet success for Windows 64?
Each target has its own library path. You have added the VT paths to the Win64 target, but need to do the same for the Win32 target.
Alternatively, remove the VT paths from the Win64 target search path, and add them instead to the target that applies to all projects, and then they will be inherited by the other projects.
In the options dialog there is a drop down control that allows you to specify the target to which your settings are to be applied.
The short answer is that the Library Path was not set correctly. And credit to David Heffernan for pointing that out.
But how and why?
The key piece that I missed was that the Library Settings dialog captures different sets of paths applicable to each of the different platform targets. So at the top of the Library Settings dialog there's a "Selected Platform" dropdown that governs which platform the settings beneath will be applied to.
To be able to build a Win 32 VCL application, the Library Path needs to be set specifically for Windows 32, which means setting the Selected Platform dropdown to Windows 32 before performing the step of adding the path to Virtual TreeView's Source directory.
Obvious in retrospect, and perhaps this SO post will help connect "Cannot resolve unit name" to this potential cause.
There are a couple of gotchas to add regarding why this happens.
a) Users coming from older versions of Delphi may be familiar with this Library Settings dialog before it handled multiple platforms, thus not realize that it now has a "Selected Platform" feature.
b) On my installation of Delphi 10.3, which is a fresh one, that "Selected Platform" dropdown reverts to Windows 64 every time you open the Library Settings dialog. It neither coordinates with the platform of the currently open project, nor does it remember what you last set it to, it seems. So it's easy to miss that it's not set to the platform you assumed, unless you know to look explicitly.
It may also be useful to know that while this functionality sets the library path for the entire Delphi installation ("globally"), there are overlapping settings at the project level, accessed as follows (for the example "Minimal" project):
Project tree, ProjectGroup1 > Minimal.exe > Build Configurations > Right-click > (Project options dialog) Building > Delphi Compiler > Target (All configurations, or particular target) > "Search path" slot.
Delphi apparently merges "Search path" with Tools > ... > Library settings > Library path.
Finally, for Virtual Treeview, its maintainer Joachim Marder has added a note to the installation instuctions to avoid the pitfall described here.

Delphi: Missing Dcu

[DCC Fatal Error] Unit1.pas(7): F1026 File not found: 'MyBitBtn.dcu'
Unit1 is a VCL Form for test purposes.
I have installed a design time package which contains a custom component that derived from TBitBtn. I can load the MyBitBtn in the Delphi IDE, load up the custom images I coded in design time and it seems like it works fine, at least visually. I get the above compile time error when I try to compile the test project.
I have a package group that has one design time package and one run time package. Design time package registers the component and Runtime package inherits the TBitBtn and has the custom code in it. The design time package contains the RunTime DCP file in the requires section.
The moment I insert the custom button on the test form, IDE creates the USES clause for MyBitBtn file. And that file apparently can't be found. Shouldn't that be part of the package installed?
Most probable you did not set 'Unit output directory' option in your runtime package, so package .dcu's are not available; I usually set it to $(BDSCOMMONDIR)\Dcp and have no problems.
Generally, the .dcu's of a runtime package should be available via global IDE library path if you want your package to be available to any project:
.
You should either use one of the existing paths or add your own.
The design part works, but for run time, the compiler must be able to find the dcu.
You can do that either...
By adding the dcu folder to the library path of the IDE.
By adding the dcu folder to the search path of the project.
Or by adding the dcu explicitly to the project.
I would choose the first option. Since it's an installed component, you would want it to be available for any project, so setting the library path makes the most sense.
define the path where this dcu is stored in system environment. And dont forget to include it in Delphi env paths.
Go to ZEOS files, open packages, choose your version(DelphiXE10/Delphi7 ...) then go to the Win 32 file, open it and open Debug folder. Copy every thing, go to Program Files, Embarcadero, Studio, 17.0, lib, Win 32, Debug and paste, do the same in every win32 folder... Hope it helps :)

How to recompile modifications to VCL source file (Menus.pas)?

We have a modified menus.pas.
At
uses ...,Controls,...;
The compiler raised a fatal error:
[DCC Fatal Error] Menus.pas(*): F2051 Unit Controls was compiled with
a different version of Menus.TPopupMenu
tried:
deleted all dcu in the project.
build
build all
tried adding the file to library path which leads to add db folder(from vcl too) and then to
[DCC Error] jpeg.pas(872): E2065 Unsatisfied forward or external declaration: 'jpeg_save_markers'
which is a dead end.
deleted the controls.dcu (all 3) and the delphi did not know automaticaly to recompile them, instead reported that controls.dcu is missing.
Here is how I handle modifications to VCL source files:
Make a copy of the file in your project structure. Either add the file to your project, or make sure the search path finds your modified file.
Make modifications, but only in the implementation section. You are not able to modify the interface section if you use any other units that themselves use the unit you are modifying.
Explicitly set the compiler options at the top of the modified source file. Use default Delphi options, as found by pressing CTRL+O O in a default vanilla project.
I'd guess that one of the final two bullet points is what is tripping you up.
In Delphi XE7 (and below) themes and styles are totally unusable.
So, I patched the file ( Delphi XE7\source\vcl\Vcl.Themes.pas ) add it to the project file, compiled it and got a DCU. I replaced the old DCU ( Delphi XE7\lib\win32\release\Vcl.Themes.dcu - same for "debug" folder) with the new one. Everything works smooth now. I don't even have to link the PAS file to my projects.

Why the compiler cannot include an external DCU in my package?

I have this error:
E2411 Unit %s in package %s refers to unit %s which is not found in
any package. Packaged units must refer only to packaged units (Delphi)
Delphi Help is extremely helpful and it says:
No further information is available for this error or warning.
Why I can't refer to a unit that is not part of a package?
UPDATE:
Never-ending story: Putting the file in its own package breaks something else: Unit GIFImg was compiled with a different version of CCR.Exif.Consts.SOutOfResources
This is why I wanted NOT to put the file in its own package.
You can't refer to a unit that is not part of a package because a package needs to be a self-contained piece of software. That means that a package must contain all units it uses or have them available through packages in its requires clause.
To solve this error you can either
include the unit in the package that you are building, or
add the package which contains that unit to the requires list of the package you are building.
Your question seems to be
Why does the compiler emit this error?
If you refer to unit A then that reference to unit A needs to be resolved. If it cannot be found in the current package, or another package in the requires clause, then the compiler simply cannot proceed.
You also ask:
Why the compiler cannot include an external DCU in my package?
You can simply add the unit to your package in the contains clause of your .dpk file.

Delphi: Required package not found

I'm trying to build 3 packages, A, B and C. A defines some base classes that are used in B and C. I've got all 3 of them in the same project group, all set up to output to the same custom BPL output folder. This folder is in the search path for B and C. But when I go to build B and C, the compiler chokes on the Requires list. "Required package 'A' not found."
How do I tell B and C where to find A so they'll build correctly?
Either the package can't be found, or the compiler is confused. In the later case, a restart sometimes helps. Then a manual build from all packages in order.
If it really can't be found, check if all package (bpl and dcp) and dcu files are available. You need both.
If this happens when the IDE is trying to load a package: your package output directory (where the *.bpl files go) has to be on your system's PATH environment variable. Packages are statically linked DLLs, Windows has to be able to find them to load them.
If this happens when building the packages: any/all of your DCP output directories (where the *.dcp files go) have to be in the dependent projects' search path so that the compiler can find the compiled packages.
You can also leave the DCP output directory of the package project empty - in which case the global DCP output directory set in Tools\Options\Library is used; the dependent projects then don't need to include it in their search path.
It is possible that the name of the required package is incorrectly specified in the 'requires' clause of the package you are trying to compile. Let's take an example:
We have two packages - VirtualTreesR.dpk and VirtualTreesD.dpk. VirtualTreesD requires VirtualTreesR. They both have the '16' suffix, so they both are displayed in the Delphi project manager window as VirtualTreesR16.bpl and VirtualTreesD16.bpl. You may think that these are the names of the packages, but you are wrong. The names of the packages are still VirtualTreesR and VirtualTreesD, not VirtualTreesR16 and VirtualTreesD16.
When VirtualTreesR.dpk is compiled Delphi produces two files (I don't talk about DCUs here) VirtualTreesR*16*.bpl and VirtualTreesR.dcp. See the difference?
Then we attempt to compile VirtualTreesD.dpk and get the error: "[DCC Fatal Error] VirtualTreesD.dpk(35): E2202 Required package 'VirtualTreesR16' not found".
The error happens because the 'requires' clause of the VirtualTreesD.dpk package contains the following lines:
requires
designide,
VirtualTreesR16;
Delphi tries to find VirtualTreesR16.dcp and fails even if the Delphi search path and the PATH environment variable are set correctly because there is no VirtualTreesR16.dcp. Only VirtualTreesR.dcp.
The solution is to fix the 'requires' clause so it will look like the one below:
requires
designide,
VirtualTreesR;
Hope it helps.
P.S. This a quite frustrating issue because this name mismatch is not obvious and its fragments are scattered across different settings. Delphi could be more specific if it specified what file exactly it tried to find (e.g. 'VirtualTreesR.dcp' instead of 'VirtualTreesR').
I would check to make sure where you are writing the .dcp files for the packages. once you have this, check that the search path of each package has an entry for the .dcp output folder.
I sometimes receive the "package not found" error when adding required packages via the Delphi Project Manager context menu. (Open a package, right click "Requires", choose "Add Reference..." command)
Instead it's easier to add the required package by editing the package project file manually:
Select the package in the Project Manager. MyPackage.bpl for example.
Ctrl+V to open the project file.
Add the required package to the requires clause.
Ensure the required package *.DCP file is in the package search path.

Resources