Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Delphi modifying its DPR (project source) unexpectedly

Tags:

project

delphi

To maintain its project, Delphi sometimes adds or removes stuff from the DPR file (project source). I quite like to format my stuff in the DPR as if it is an ordinary unit, for example to group together the 'used' frame references and project source files. I make copies of it and can go back when this happens but every so often, I'll notice that the DPR has had all its source file references smashed into a single block.

Anyone else suffer from this? Is there any way of preventing this from happening (other than a read-only file). Thanks

like image 640
Brian Frost Avatar asked Jul 20 '11 12:07

Brian Frost


1 Answers

What I do for most of my projects is to have these 2 files:

  1. MyProgram.dpr
  2. MyProgramUnit.pas

MyProgramUnit has a public method Main that contains all the logic from the .dpr (including any conditional defines)

MyProgram just calls Main.

Edit 1:

You can put uses lists in MyProgramUnit.pas, but they don't automatically become part of your project. That might or might not be an issue, it depends if you like having Delphi finding units in a search path, or add files to your project to make them visible.

What you can do, is to document the uses-lists in MyProgramUnit.pas and group them by cause. This is what I normally do in most units anyway, not only in the main unit.

Edit 2:

Don't go the {$I MyIncludeFile.inc} way.
Delphi - especially the IDE - is bad with include files. Code Completion, etc, fail at irregular places.

I've been heavy on include files in the past; not so any more. I even stopped using them for defines, and moved from {$IFDEF define} ... {$ENDIF} towards {$IF Constant1 >= Constant2} ... {$IFEND}.

like image 159
Jeroen Wiert Pluimers Avatar answered Oct 06 '22 00:10

Jeroen Wiert Pluimers