I have used C++ in Unix and I am aware of .h and .cpp files, but I have never worked on C++ builder and now I have got a project that contains .cpp, .h and .dfm files. So what is the the purpose of .dfm files and how do we use it?
Thanks in advance.
dfm files describe a form, and typically have an associated cpp file and h file for other aspects of the form's class. They are typically edited using the IDE in C++ Builder.
Related
I recently got project in delphi which I need to rearange, I'm totally new in delphi so I'm searching my way in environment and language. Question, in my project group I have two files with .dproj extension, no corresponding .dpr file so when I try to load them I got msg:
"Canot open file xxxx.dpk, system cannot find the file specified"
Did the old programmer forgot to copy all files so I'm missing this, or is this some kind of file (.dproj) that I only add as a reference so I don't need to have corresponding .dpk or .dpr file??
The .dpk file is the top level Pascal source file for a package. It is the package equivalent of an application project's .dpr file.
The original developer should have supplied it to you. Ask them to do so.
Every single time i either try to open or add a resource file to my project or just open it within delphi it will throw me an error (I have tried .rc,.res,.rc..all kinds of extensions) and it will say that the file has been truncated or that Delphi cannot open or add this type of file. any ideas?
You cannot open a .res file in the Code Editor, as it is a binary file. You can open an .rc file, as it is a plain text file.
You can certainly add both .rc and .res files to a project, though. The IDE should not complain about that.
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.
In C++ Builder when I compile I get
[ilink32 Error] Error: 'C:\PATH\TO\A\LIB\INCLUDED\IN\THE\PROJECT\ALIBRARY.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
When I convert .lib with utilities coff2omf, new lib looses significant functions.
C++Builder cannot use .lib files from other compilers, only its own.
If the .lib file is an import lib for a DLL, use C++Builder's command-line IMPLIB tool to create a new .lib file from the DLL directly.
If the .lib file is a static library (containing actual code), C++Builder's command-line COFF2OMF tool MAY be able to convert the library, but it is not guaranteed. It really depends on what kind of code the library is actually using. If the conversion is not possible, you will have to wrap the .lib file into a DLL that is written in the same compiler that created the .lib file. Then you can use the DLL in C++Builder.
I was facing the same issue. I have used the tool COFF2OMF to covert the existing lib files to make them compatible with C++Builder. It works for me.
Syntax:
..Embarcadero/../bin> COFF2OMF libssl.lib alibssl.lib
..Embarcadero/../bin> COFF2OMF libcrypto.lib alibcrypto.lib
Renamed the converted files and placed them in the required location.
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