How to add a cpp file to an existing project in Borland C++Builder 5? - c++builder

Adding the line #include "newProc.h" to unit1.cpp and unit1.h is not enough. It leads to an error:
[Linker Error] Unresolved external 'newProcClass::newProc()' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\TEST1\UNIT1.OBJ
(newProc.cpp was not compiled)
Make or Build Project1 with unit1.cpp's line #pragma link "newProc" (obj) is ok, but I want to compile the newProc.cpp in each Make or Build process.

Borland C++Builder 5 is very old - but I am pretty sure it still has a project view which shows the files used by the project. Right click on the project and select "Add..." and then navigate to the .cpp file you want to add.
If you use the main menu: File | New, and then select either VCL Form or C++ unit (the latter if you are going to develop a C++ file with no VCL GUI, can still use VCL helper functions and classes), then the file is automatically added to the project, and you don't have to do the above procedure.

Related

Unresolved External After Project Migration

I'm using C++Builder 10.4.1. I've migrated a simple project containing 3 forms. The main form contains a TDriveComboBox. When I try to compile I get these errors:
[ilink32 Error] Error: Unresolved external 'Vcl::Filectrl::TDriveComboBox::' referenced from (then it lists the path to the main form's OBJ file)
[ilink32 Error] Error: Unresolved external '__fastcall Vcl::Filectrl::TDriveComboBox::GetDrive()' referenced from (then it lists the path to the main form's OBJ file)
I've even tried to delete the TDriveComboBox and replace it, but that doesn't help.
What's the problem and how can I fix it?
I would:
delete all temp files (obj,exe,tds,...)
add new temp TDriveComboBox on form with this problem
compile and run.
If that does not help then sometimes manually #include VCL header containing the component into form *.h file helps reset the compiler/linker so search the VCL inc folder for TDriveComboBox In mine system its in here:
c:\Program Files (x86)\Borland\BDS\4.0\include\vcl\FileCtrl.hpp
So add something like:
#include <FileCtrl.hpp>
or
#include <vcl\\FileCtrl.hpp>
into your form *.h file... but even this sometimes fail. In my experience the problem lies in the project file (*.bds, *.bdsproj, ... or whatever extention the newer versions got) so its a good idea to backup it while the compiler works as should... As it sometimes corrupt it self especially for big projects.
Sometimes also helps if you move:
#pragma hdrstop
line to different locations (few lines down or up). If you're lucky it can also reset the compiler/linker after which you can move it to original location. However this helps only occasionally (like 1:20). And you also need to try few locations
In case nothing works just create new empty project and copy the forms and stuff into it and add it to project... Each form has 3 files (*.h,*.cpp,*.dfm) and do not forget to add to your project whatever you need (DLL *.lib,...) if its not linked directly with #pragma link for all the 3th party custom stuff your app uses
Once (also after migration from BCB5 to BDS2006) even this did not help for one of mine projects. I was forced to create also the forms (with all the components but without functionality just place them on forms) and then copy the stuff from old App... However if you got too many components it will be a pain in the ...
I have found for most of these problems created by the ide in converting my 10.3.3 projects to 10.4.1 can be solved by an annoying process as described below:
open the form.
on design tab, switch to text view.
switch to form veiw.
under project, recompile just the form.
now run project.
This has solved most of my unresolved's except _CG_*.

Can I have Delphi automatically compile RC files?

I thought Delphi would automatically compile resource files when I add them to my program, like
{$R 'resource.rc'}
but the linker returns an error message Error reading file "D:\resource.rc". When I look into project options, however, brcc32.exe is explicitly listed as resource compiler to use:
I know I can invoke the resource compiler from the CLI, but I'd prefer to have resources compiled automatically. How can I do this? I'm using Delphi XE8.
You need to add the resources to the project using the Resources and Images item on the Project menu.
#Joris Grootman I know I'm VERY late to the party, but as another alternative you could set up a "pre-build" event in Delphi (Project Options | Build events | Pre-build events | Commands) to run the resource compiler command before the project builds, and since it's just a quick process you should not notice it slowing down the Delphi build.
Its better and more flexible to list all of your resources in an RC file and then add this file to your project (Project > Add to Project), The IDE will add the $R directive to the project's DPR file, and the RC file will now appear in your project files pane where you can double click it to open it in the editor so you can add/edit/delete resource as you wish.
This way, Your RC file will be compiled automatically and linked to your executable whenever you compile your project.

link obj files in embarcadero c++ builder Dunit Test Project

I'have added a test case to DUnit Test project in embarcadero c++ builder 2010. I can compile it fine but the linker fails saying "unresolved external" to a method in an .obj file from original project. If I add the .obj file to DUnit project it works fine. However I don't want to do it as there are huge number of .obj files in the original project and it will be a pain to add .obj files each time you want to test a new class. Is there a way to point the linker to search directories to look in for .obj files and get them from there. ( I'm not using the command line, but the c++ builder 2010 IDE).
If you go into Project Properties you can configure the directories that are searched for includes, libraries, etc. You can do this by build type or for all configurations.
However it's usually a bad idea to directly link other .obj files from a different project, as they may have been compiled with different settings . Why don't you just add your test case to the project without deleting anything from it?

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.

Resources