Files Explanation

So, now you know what bits are what in the interface, what about the files?

More interestingly; what hapens if you break something... Which is easier than you might think.

What are the files?
  • .PAS - Pascal Source Code; Contains your program code. **CRUCIAL**
  • .DFM - Delphi Form Module; Contains the graphical setup of your Form in a human readable format. **CRUCIAL**
  • .DPR - Delphi Project; Contains the anchor source that links to all other units and initiates the program. Use this to open your Projects! (Assuming you are doing GUI programming, otherwise open the .PAS files) **CRUCIAL**
  • .RES - Resource file; contains information about icons and other things you may want to include in your project. This file is deletable, but may cause problems if you include program icons into it (but you probably won't :P )
  • .DCU - Delphi Compiled Unit; This gets produced when you compile, its the object code that gets linked to make the final .exe file, and can be deleted.
  • .~* - anything with a ~ in front of the extention is a backup from the previous save. VERY USEFUL! But, deletable if you are happy that you have back ups.
  • .CFG - Configuration file; contains compiler directives (so it knows what options to turn on and off) and some linker info. Deletable.
  • .DOF - Delphi Options File; Similar to the .cfg, deletable.
  • .EXE - The final executable; Deletable providing you have the all the source. 'Cos you can just re-compile it :-)
There may be a couple of other files kicking about too if you do some weird stuff. Like a .TODO if you are organised (I think that one is self explanatory...)

And what do I use?
Well, the .pas files are what get loaded into the editor. So, you use these all the time.
If you accidentally delete a large wad of code, then you have several options...
  • ctrl+z till you go blue. Delphi has amazing undo support; it can go in blocks, single characters, and even records strange things like what you highlighted. It can be set to drop undo's after a save (which I would turn off, personally) and these options can be found in the Options (surprisingly) which I will mention later.
  • Use the .~pas files. Firstly, open it in notepad or similar, then check its the right code, it should be from your last save (which you should do regularly with ctrl+s). If it is then you can either copy it out and overwrite the code in the editor, or close Delphi and delete the .pas then rename ~pas to pas. NB; BE CAREFUL! If you have added methods (Procedures or Functions) or objects to your project since your last save, then you may have a synchronisation problem with your .dfm file.
There is an issue with some component that seems to exist.. or doesnt.
This happens after reverting to old .pas files or sometimes if you randomly delete stuff that you probably shouldn't (It happens, by mistake, often).
  • Check that all the components listed in the head of your .pas file exist on the corresponding form.
  • This list should match:
  • If not, then you have a problem. Try removing components from the form (simply by clicking and deleting) if they appear in the latter list but not the former. If they appear in the former but not the latter, then you need to comment out the offending code in the former (Don't worry, this is safe, comments are undoable; just put // before the line). After commenting out, add a component of the same type to the form and rename it to match the commented component. This *should* fix it, if not, you may have to poke around in the DFM in notepad, after closing delphi.
Hopefully this won't happen. It can do if your it crashes part way through a save, or if you mess about with the lists.

Another problem is versioning...
If you are sensible, you will make backups. This is good. However it can cause problems;
  • Ensure that all the files you think you are editing are the real files. This can be done by checking the file paths in the .dpr (Which can be opened by clicking the , its the one named the same as your project)
  • DO NOT use the save as button in a project! It actually saves the current file (in the editor) or the project (if you are not focused on the editor) as a new file, but continues to write to all the other files as normal. It causes all sorts of problems, so unless you are working on a single .pas file (e.g. for console applications) don't use it.
  • Use the save all button! always! it is your friend. or ctrl+s, regularly!
You should not have any other real problems with the files and saving and such. If you make a backup, zip it or something because pas files floating around all over the place is horrid. I always save like this:
ProjectsFolder                      where all the projects are
    NewProjectName             the new project you are working on (save the PROJECT here, not the units)
          Units                           put units in here! Easy.
That will save a lot of bother, trust me.

stringfellow wrote this guide

Page last modified on Wed, 21 Nov 2018 17:37:18 +0000