I am developing a package of IDE-registered components, most of which are derived from a base TFrame class. There are also various custom dialog forms that are called by these components, included in the package. I'm working in Delphi 2007.
I'm noticing that sometimes frame and form units, which normally have an associated DFM file, do not always show the DFM file "underneath" (accessible via the little [+] treeview node expander) underneath them. If I add an existing form-based PAS file, for instance, via right-clicking on the BPL project (in the Project Manager) -> Add, it doesn't show the DFM file in the listing.
If I Add New, though, and create a new form or frame unit in the project, it shows as the typical nested two-file item in the Project Manager. It also shows that way if I drag an existing form from another project in the Project Group to this BPL project in question.
Seems like this should be consistent, and I prefer both files showing when the unit is a Frame or Form.
Is this indicative of something wrong in the project file? Am I adding existing forms/frames to this package incorrectly? If so, how should I add existing form/frame units so that both files show in the Project Manager listing?
* UPDATE *
From Alen's suggestion below:
I tried adding the {$R *.dfm} directive to the form's unit, and it did not force the DFM file to show up when adding it to my BPL package/project. Adding {$R *.dfm} to the project file itself (which I don't think is what you meant, but I thought I'd try it) didn't work either. Does this technique only work with EXE projects?
Possibly (likely) related, trying to build with that directive in places gives me this:
[DCC Error] E2161 Warning: Duplicate resource: Type 10 (RCDATA), ID TTESTTREEVIEW; File E:\Projects\MyApp\Components\TTestTreeViewFrame.dfm resource kept; file
E:\Projects\MyApp\Components\TTestTreeViewFrame.dfm resource discarded.
"Keping" and "discarding" the same file??
Later: It looks like this "duplicate resource" issue MIGHT be related to
this. Not certain, but at least in one instance both happened simultaneously.
Vegar is on the right track. In order for the project manager to display the .dfm node, it needs to know that a form/frame/datamodule is associated with the pas file. It looks at the {Form1} comment in the .dpk or .dpr file for this information. If, when adding a file to the project, the IDE doesn't recognize that there is a .dfm associated with it, make sure the .pas file has the {$R *.dfm} directive in the clear. By that, I should not be buried in an IFDEF or otherwise obscured by potential syntax errors in the file. The IDE uses the presence of this directive to decide whether or not it should try and open the .dfm in the designer.
The IDE doesn't just take for granted that if there is a Unit1.pas and a Unit1.dfm, that they are really supposed to be together. Consider that you created a new form unit and it was called Unit1. Now you deleted just the Unit1.pas and then just went and created a new unit which would be given the name Unit1.pas. There is no reference to the old, stale Unit1.dfm out there on the disk from this new, same-base-named, Unit1.pas. It would be strange and confusing if the IDE were to just blindly open that .dfm.
If you take a look at the project source for the package, you will find a difference in the Contains-section:
contains
Unit2 in 'unit2.pas',
Unit1 in 'Unit1.pas' {Form1};
Unit2 will show as a single unit, and unit1 will show as a unit with a form.
As you can see, unit1 has a {Form1} comment that unit2 lacks.
I do not know if it's possible to add an existing unit so that this comment is automatically generated.
Another reason for anyone else that is looking for another solution is when you rename pas file close all files and reopen. The previous version will reopen & must be removed with previously named added to project
Related
I´m using Delphi 7 and have a new unit which I would like to use in my project. I already compiled the new. When I try using this unit in my project by adding it to the uses clause, it comes out the an error saying .dcu file not found. I also tried putting the full path of the file in the uses clause, but that still didn't work. I have already search for the respective .dcu file and it was nowhere found. It seems it was not generated... Can anyone give a hint how to solve this? Thanks, Ana
Delphi is not going to find your new unit by only adding it to the uses clause. You also have to add it to the actual project. There's no need to keep track of the .dcu file(s), as they're already compiled and cannot be modified. If I remember right, in Delphi 7, go to Project > Add Existing File > Pick your .pas file. Adding a unit to the uses clause presumes that the file is already included somewhere that Delphi can find.
I happened to notice a <DCCReference> tag that referenced a file that didn't even exist. What is the point of these tags? What would be the consequences of deleting them?
Thats the XML it uses to store what the project is. If you add anything to the dpr file it changes the dproj to suit. If you add a file to the project from the ide it changes both the dpr and the dproj. You can delete the entry, its self repairing to some extent. Also, a file does not need to be in here to be included in the compile. If a unit has it in it's uses clause then it will be pulled in.
If it keeps coming back then remove the unit from the project in the ide. If its not there then remove it from the dpr.
Finally 2007 has a bug where it can add multiple variations of a file name into the dproj. You have to delete the offending ones manually.
I have a .BPG project which has a collection of .DPR project files.
Opened a .PAS file
I changed some line of code in a .PAS file of an project.
Saved it
After changing the source code, I tried COMPILE on that project.
First it says "Compiled" successfully.
Now I see the same .PAS file, the changes were lost. Codes changed at step 2 was lost. It is having the previous code only.
The behavior is same for BUILD too.
Anyone knows about this problem?
Thanks in advance.
Update
One more hint:
.DPR Project Name is XX.dll In IDE, there is one file with name XX_TLB.PAS in that project. In this file only I tried to change some code, which got reverted after compiling/building. Now I tried to rename this file, which gave me a error message
Type Libraries must have the tlb extention.
Also can the .DCU and .PAS files be in the same directory? I entered this directory (where both .PAS and .DCU files exist) into the directories list under "Tools->Options->Delphi Options->Library - Win32"
XX_TLB.PAS files are protected files. Do not edit such files directly. In fact there is note on top of the file warning you from editing the file.
They are regenerated each time the type library is refreshed.
See Code Generated When You Import Type Library Information.
This refresh could be done by the IDE each time you compile/build your dll.
You will never edit this file because of the dependencies of a type library and registered com objects. Either you change the com object itself via the type library editor, or create a new unit that interacts with your ActiveX class.
The Delphi IDE doesn't undo changes, as a general rule. There's notable exception. When you create an empty event handler, and then save the source file, the IDE will remove that event handler. Perhaps that's what is happening.
The other possibility that occurs to me is that you have multiple copies of the file. I've known the following to happen:
You create a package containing Unit1.
You install the package.
You then make another project that contains a different Unit1. Perhaps a copy of the file in a different location, so that it looks like the same unit.
You then modify the copy of Unit1, but the IDE sometimes prefers to open the file from the package.
The bottom line is that beyond deleting empty event handlers the IDE won't undo your changes. So it seems extremely likely that you have multiple copies of the file. To get to the bottom of this, you need to get the full path to the file. In the IDE, hover over the tab with the filename and the IDE will display the full path in a hint. I suspect you'll find that you have two distinct files.
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.
I have an old Delphi codebase I have to maintain, lots of DLLs, some older than others. In some of these DLLs there is no version information in the Project Options dialog. The controls for adding a version are greyed out and I can't even add a version number by manually editing the .DOF file. How can I include a version number in these projects?
Check if the default .RES file exists in the project source location. Delphi includes the version number of the project in a .res file with the same name as the .dpr file. If the .RES file does not exist, the simplest way to recreate it is to add the {$R *.RES} compiler directive to the .DPR file, immediately after the uses clause.
library foolib;
uses
foo in 'foo.pas',
baz in 'baz.pas';
{$R *.RES}
exports
foofunc name 'foofunc';
end;
As soon as you add the {$R *.RES} compiler directive Delphi will tell you it has recreated the foolib.res resource file.
It seems the resource directive {$R *.RES} is missing (or enclosed in conditional defines) in your .dpr file so that the IDE doesn't find it.
You can create and embed resource files in libraries created under Delphi, by using the $R directive.
This link has information relevant to constructing the RES file.
Delphi has its own resource compiler: BRCC32
I use a build control system (FinalBuilder) and that is able to add version resources to all my DLLs and EXEs that are all coherent. Therefore I can be confident that the file set is all labelled with the same build. There are some Delphi projects that don't have versions by default, and FB will add them for you anyway.
Inclusion of version info in dll's is a bit erratic. If you specify a lib_suffix the version info is not updated.