How to add a new (self-made) unit to a project - delphi

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.

Related

What are <DCCReference> tags for in Delphi .dproj files?

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.

Delphi .PAS code reverts to the previous code after compile/build

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.

How do I make my changes to XML-related source files take effect?

I want to make changes to the xmldom and XMLDoc files. I tried to, but I don't know how to test those changes because the program does not seem to be running the code in those files. I tried using a ShowMessage to see if that code was being accessed but it never showed up. Even if I rename the directory the files are in, the program still compiles fine as if it is not actively reading the files at run time but instead has the information stored elsewhere.
How can I change these namespaces and then make sure that the changes are being included in my next compile?
Update
Well i'm looking for an answer in general.. Because I have had this problem in multiple situations.. But for specifics Changing XML node attribute value gives "Namespace error" (here the answer talks about changing the 'AdomCore_4_3') I want to be able to change it and have the change show up when I compile.
If you've removed the compiled DCU files from your environment, and your changes still aren't being compiled into your project, then you either aren't really using those units at all, or you have run-time packages enabled.
With run-time packages, the compiled code is accessed from the BPL file, not the DCUs. You're not allowed to distribute modified BPL files, so if you're going to modify the Delphi-provided source code, you need to make sure you're not linking the package with the XML units to your project. You can control that in your project's linker options.
As long as you are not making changes in the interface section of the units, only the implementation section, then you can disable use of Runtime Packages in your Project Options and then add the modified source files directly to your project. The compiler will compile them into new .DCU files and use them instead of the default .DCU files.

recompile/rebuild Delphi 5 code using .dpr file

I am trying to recompile/rebuild an old application program developed on Delphi5. I used the same Delphi5 software on an XP computer.
I did some minor corrections to the codes of a couple of forms and units. When I recompile using the .dpr file it comes with a fatal message: File not found System.pas
I added in .dpr file on the link path to this file BP folder. No success and the same message. Any clue will help.
Probably Library Path is broken after running some buggy component installer. In modern IDE's look for Tools -> Options -> Library -> Library Path from main menu (should be slightly different for Delphi 5).
System.dcu file lives in $(BDS)\Lib path for Delphi 2007.
The "File not found System.pas" error often isn't really because it can't find system.pas. It's some other problem that manifests as this error.
It can be:
Duplicate Path entries in the Library Path.
Too many entries in the Library Path - I think the limit is 99.
Path to a package in Library Paths too long.
Path to a package in Library Paths corrupt.
Environmental Variables not set correctly.
and possibly more if you Google "system.pas not found"
Marjan is right.
But also add ${DELPHI}\LIB\OBJ
If you still have a dcc32.cfg with the project, or a .cfg with the project, open it up to see if the settings in there are correct. Otherwise delete the .cfg or edit it to reflect the proper path to the bin and bin\obj directories.
A .dpr file is the main project file for a Delphi 2,3,4,5,6,7 project.
You have not given any details like WHAT WAY OF BUILDING SOMETHING of delphi you're using (the code is Delphi 5 level code, but you are not telling me for example, if you built the project inside the Delphi IDE or from the command line compiler DCC32), and what other files you have installed. You haven't mentioned if the library paths and so on are configured (either for the IDE, or for the command line environment, both of which are separate tasks).
An inability to find System.pas suggests to me that you might be running the command line compiler (Dcc32) instead of the IDE to build the project, and you have forgotten to mention that. That usually means you have to set up the Options (dcc32.dof) file for Delphi, so that command line building with Dcc32 can work.
What exactly do you mean by "When I compile with the .dpr file"? Instead of making people guess, show the commands you typed, exactly, and the error message, exactly. If it helps, use screenshots or text grabs.

Delphi Error E1026 File not found: "myprojectname.tlb"

I have a project let's call it Yellow.dproj, which I saved as Blue.dproj, to make some changes. There must be some COM/DCOM related code in this project, but I can't figure out where.
The error I am getting when I try to build Yellow.dproj is that it can not find a type library (TLB) file: "E1026 File not found: ". The file it can't find is MyAppName.tlb. There is a MyAppName_tlb.pas file, which I have tried adding and removing from the project, either way I get this error.
I think I probably have to go into that TLB file, which I don't really understand, and rename a bunch of junk in there, because it is dependant on the name of my application. This is something that happens to you, I suspect, when you use COM/DCOM and type libraries in Delphi (Delphi 2010). You can't just rename or save-as and build a new project again.
What do I do to fix this unit up?
Do you have {$ *.TLB} in your project source?
The * is the project name, so the TLB file has to match the name of the project - perhaps the name of the tbl was not changed along with the project.

Resources