Whats identifies a 'Unit' in Borland/Embarcadero CBuilder IDE - c++builder-6

I have a number of c++ projects were units were added. After working a while on these projects some of these units change into a .cpp file and a .h file with no connection between the two anymore.
When I click the header file in the "project manager", the .cpp file gets focus in the IDE. I have to right click on the .cpp source and choose "open source/header file" to open the header file. Normal behaviour in a unit is a set of tabs below the source window to choose between source and header.
How can I restore this?

The .cpp and .h files need to have the same base name, eg <name>.cpp and <name>.h, for example Unit1.cpp and Unit1.h. And the .h file needs to have a header guard named <name>H, for example Unit1H. Then, the IDE will treat the files (and any associated <name>.dfm file) as a single "unit".

Related

Erlang : exception error: no match of right hand side value {error,enoent} while reading a text file

I am currenly working on an erlang project and stuck in reading the file. I want to read a text file which is in the /src folder where all the erlang and a text file are in the same structure. Then too, I am not being able to read the file despite of specifying file paths. Any help would be appreciated.
start() ->
{ok,DataList} = file:consult("Calls.txt"),
io:format("** Calls to be made **"),
io:fwrite("~w~n",[DataList]).
The data file stores contents like : {john, [jill,joe,bob]}.
Try add folder name to the path or try set full patch to the file:
1> {ok,DataList} = file:consult("src/Calls.txt").
Notes: the error {error,enoent} mean that the file does not exist or you don't have a rights to read/write current file, for this case need set 777 rights or similar.
If you need to use src/call.txt, then this simply means that your IDE (or you) has created a src folder in which the calls.txt file has been placed. At the same time, the IDE is using a path that only includes the top level folder (i.e., the root folder for the IDE project). So src/call.txt must be used in that case. This isn’t a problem with Erlang, or even the IDE. It’s just the way your project is set up.
You can do either of two things. Move the calls.txt file up one level in the IDE file manager, so that it can be referenced as calls.txt, not src/call.txt. You can also just change the path to “calls.txt” before you run it from the command line.
enoent means "Error: No Entry/Entity". It means the file couldn't be found. When I try your code, it works correctly and outputs
[{john,[jill,joe,bob]}]

Delphi {$INCLUDE filename} in uses part of dpr file

I have many Delphi 10 projects that are using the same units, let's call them "commons".
When I add anew unit to commons, I have to manually add it to each project. I have tried adding a {$INCLUDE commons.inc} line into the uses part of each .dpr file:
uses
Forms,
{$INCLUDE commons.inc}
projectUnit1,
...;
commons.inc has this content:
common1,
common2,
I can compile a project but cannot manage the units from commons.inc. By manage, I mean Ctrl-F12, remove from project, etc.
This is from Delphi's help:
There is one restriction to the use of include files: an include file can't be specified in the middle of a statement part. In fact, all statements between the begin and end of a statement part must exist in the same source file.
I suppose that is why my idea does not work?
Am I doing something wrong, or is there another solution?
This workaround might suit. The only downside I have found so far is that the included files do not appear in the Project Manager.
Add the folder(s) containing the files to be included to the search path of every project.
Create Include.pas, a normal .pas file, and include it in the normal way in every project.
Add the files to be included in multiple projects to the uses clause of Include.pas. $IFDEFS can be used if required.

Delphi 7 and .dfm files get the forms displayed?

I'm a beginner. I have received a .rar file containing a bunch of files. I think that they are used to generate Forms.
Here's an example:
BackupManager.dfm
BackupManager.pas
WaveControl.dfm
WaveControl.pas
So, can anyone help me understand exactly how to use them?
A .dfm file contains the property values and sub object definitions of a Form. The .pas file that has the same base filename as the .dfm file contains the Delphi Pascal source code for the Form, its event handlers, etc.
To use these files, simply create a Delphi VCL Forms project and add the .pas files to the project. Each .pas file should have a {$R *.dfm} compiler directive in it to link to its associated .dfm file.
The compiler will compile each .pas file into a .dcu file and link it into the final executable, and will also create a separate binary resource for the content of each .dfm file and link them into the executable as well.
When the executable is run and it tries to create an instance of a Form class (either automatically at startup, or explicitly in code), the RTL will automatically load the appropriate DFM resource and parse it to construct the necessary sub objects, assign their property values, and hook up their event handlers.

Add translation using PoEditor

I have files named en_US.po, ru_RU.po etc.
Editing *.po files in PoEdit is very useful, but not while adding new strings manually.
How can I easily add new translation strings which are not automatically detected by PoEdit?
You can edit *.po files in any text editor and then in POEdit generate *.mo file
You misunderstand how gettext translations work. Source strings for translation are extracted from source code. It doesn't make sense to add them manually — they would never be used if they didn't have corresponding source code that uses them.
So the way to add strings is to use xgettext or Poedit's update from sources functionality.
P.S. The name's Poedit, not PoEditor.
You can configure your project (*.po file) opened in PoEdit. If you will done that correct PoEdit automatically update what to translate in this opened *.po file.
First of all, open *.po file which you want update with strings to
translate.
Go to Catalog -> Properties then to Source Paths tab
Add paths where PoEdit should look for source files in Your applilcation. More universal is to use relative to opened *.po file main path. If you have typical zf2 skeleton application folder structure you can add ../../.. for main path and add one module path.
Then go to Source of keywords tab and add translate and if you're using zf2 forms it is useful to add addLabel keyword (PoEdit will scan sources for this functions and add string parameters from them to your *.po file, as string to translate)
Next open Edit -> Preferences and in Processing programs tab, edit PHP section and add *.phtml extension (this will be scanned by poedit also)
After that you have to click in Update button and PoEdit will start scan your sources for strings to translate. Then you only have to do is translate found strings.

Delphi DFM not found

I am having one xyz.pas file reference in my project. But that file is not with me. I am having the xyz.dcu and xyz.obj file of that xyz.pas file.
When I tried to compile the project I have got the Error "xyz.dcu not found". So i have included the path of xyz.dcu in Search path. Now I am getting error "xyz.dfm not found".
Please suggest me the solution. Is it possible to compile the project with only .dcu and .obj files?
Thanks in advance.
Regards,
Naren
I hope you haven't lost your work.
Simplified, Delphi works like this:
PAS+DFM => DCU
DCU+RES => EXE
More about Delphi files at the end of this answer.
You can compile the project if you only have the DCU file. First, remove the PAS file from your folder else Delphi will try to recompile it (and in order to recompile it, it needs the DFM file).
I don't think the Obj file will be of any use to you.
The DFM file is very very important for your project but yet not critical important. If you are in deep need, you can still go on without it as it can be reconstructed manually based on information you have in the PAS file and based on the way the application's GUI looks (if you have ever seen it running).
Here is the trick (involves some work):
Just create a new form and then look at the top of your original PAS file for the declaration of the form. It may look like this:
TYPE
TYourForm = class(TForm)
xLabel: TLabel;
yButton: TButton;
etc
etc
end;
Then put all those controls back to your new form and name them exactly as they are named in the PAS file (xLabel, yButton, etc). Arrange them to resemble the original GUI. When done, replace the new created PAS file with your original PAS file. IMPORTANT: the name of the DFM and PAS file should match. Compile and you are done! The rebuilt GUI may not look EXACTLY as the original one, but it should do it.
Hint:
There are tools that can extract the DFM file from DCU/EXE.
Here are some of them: www.delphi2.software.informer.com/download-delphi-extract-dfm
This will help you a lot!
.PAS - Delphi Source File
PAS should be stored in Source Control
In Delphi, PAS files are always the source code to either a unit or a form. Unit source files contain most of the code in an application. The unit contains the source code for any event handlers attached to the events of the form or the components it contains. We may edit .pas files using Delphi's code editor. Do not delete .pas files.
.DCU - Delphi Compiled Unit
A compiled unit (.pas) file. By default the compiled version of each unit is stored in a separate binary-format file with the same name as the unit file, but with the extension .DCU (Delphi compiled unit). For example unit1.dcu contains the code and data declared in the unit1.pas file. When you rebuild a project, individual units are not recompiled unless their source (.PAS) files have changed since the last compilation, or their .DCU files cannot be found. Safely delete .dcu file because Delphi recreates it when you compile the application.
.DFM - Delphi Form
DFM should be stored in Source Control
These files are always paired with .pas files. Dfm file contains the details (properties) of the objects contained in a form. It can be view as text by right clicking on the form and selecting view as text from the pop-up menu. Delphi copies information in .dfm files into the finished .exe code file. Caution should be used in altering this file as changes to it could prevent the IDE from being able to load the form. Form files can be saved in either binary or text format. The Environment Options dialog lets you indicate which format you want to use for newly created forms. Do not delete .dfm files.
source: delphi.about.com/od/beginners/a/aa032800a.htm
If you are still in the possesion of the executable, then you can extract your complete and original DFM file from the application resources by any arbitrary resource manager. For example: XN Resource Editor. In the RC DATA category, there will be an item called TXYZ.
Delphi 20xx/XE
Note that Delphi saves old versions of your files in a hidden subdir of your project dir called __history.
In that dir are saved versions of your .pas, .dfm and other project files.
These files are created every time you save a change to disk.
Do a search on your harddisk for all files, (including hidden ones) named *.~*~ this should bring up any backup source files you may have.
They will miss the last change(s) you made, but at least you will not have to do everything all over again.
Delphi 7 and before
Delphi 7 saves these files in the same dir as your project files with a .~ extension.
DFM-Files hold the "visual" aspects (controls, components, properties, visuals, data...) of a (say) form. If the PAS-File (or the compiled DCU-File) needs the DFM, you have to have it, or you get this error. There is no other way than to have the DFM, i think.
Correction (as written below, sorry!): you can compile with only the DCU-file if you remove the PAS-file and provide ONLY the DCU-File. In this case the DCU-File must be compiled with the same compiler-version to be linked into the App, because the compiler can not recompile the DCU.
This is pretty late, but here's what I came with.
My directory stucture is like this
/ Project
/ Source
/ Unit1.pas
/ Packages
/Delphi2010Berlin
/ MyPackage1.dpk
/ MyPackage2.dpk
/ Library
/ Delphi2010Berlin
/ Win32
/ Debug
/ Release
In the /Project folder, i created a .bat file named 'dfmcopy.bat'
All it contains is
#echo off
for /r %1 %%x in (*.dfm) do #copy "%%x" %2 /Y >NUL
Then, in my post build event for my .bpl
./../../dfmcopy.bat $(PROJECTPATH)\..\..\Source $(PROJECTPATH)\..\..\Library\$(Platform)\$(Config)
This will recursively copy all .dfm that are contained in the /Source folder into the /Library/{DelphiVersion}/{Platform}/{Config} folder
One caveat is that if you have multiple projects that have this post build event, dfms might be copied over and over for each project. Don't know if that can pose any issue now.
I use apache ant to build delphi project.
I fix the "dfm not found error" by deleting all dcu files and seperating compiler output files from source files.
The problem is probabily caused by wrong path of dcus files.
<project name ="app1" default = "run">
<property name="delphipath" value="your delphi path"/>
<property name="source" value="C:/ws4d/TStateMachine-master/Tests"/>
<property name="dunit" value="C:/ws4d/dunit-svn"/>
<property name="DCUOUT" value="C:/ws4d/TStateMachine-master/Tests/BIN"/>
<target name="run">
<!-- Compile with Delphi 6 -->
<apply executable="${delphipath}/bin/dcc32.exe" failonerror="true" output="build-dxe10.log" >
<!-- rebuild quiet -->
<arg value="-B"/>
<arg value="-Q"/>
<!-- file paths -->
<arg value="-I${source};{dunit}/src"/>
<arg value="-U${source};{dunit}/src;{delphipath}/lib/win32/release"/>
<arg value="-R${source};{dunit}/src;{delphipath}/lib/win32/release"/>
<arg value="-O${DCUOUT};"/>
<arg value="-N${DCUOUT}"/>
<arg value="-E${DCUOUT}"/>
<!-- all *.dpr files in current directory -->
<fileset dir=".">
<patternset><include name="*.dpr"/></patternset>
</fileset>
</apply>
</target>
</project>

Resources