Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

Anyway to prevent Delphi from automatically touching uses clauses

I find it most annoying that Delphi insists on helping you by tweaking your uses clauses and would like to know if anyone has found a way to turn this off. I'm even willing to write an OTI plug-in for the IDE if it can be handled that way, but I hoping its just a checkbox I've overlooked. The way we structure projects these features are a much bigger annoyance than help. It also adds unnecessary coupling to the project. Specifically:

1) Adding a unit, automatically adds it to the DPR uses clause when 99.9% of the time it is never needed there AND (without warning) wipes out any conditional defines you may have in the uses clause as part of the process.

2) Adds tons of unnecessary units to the interface uses of and unit with a dfm every time you touch the file. Makes it virtually impossible to keep a lean, structured uses clause if a form is involved.
0
GTDGuy
Asked:
GTDGuy
  • 6
  • 5
  • 4
  • +1
3 Solutions
 
Geert GruwezOracle dbaCommented:
nope
0
 
mikelittlewoodCommented:
A unit does not have to be included in the .dpr, but if your application is using it you would have to have the unit located in the project library/search path as a minimum for it to compile. This doesn't mean that it will reduce the size of your .exe though as the units will still be compiled with the application.
0
 
Geert GruwezOracle dbaCommented:
if you use components on the form, the units for these components are mostly automatically added.

1) Adding a unit, automatically adds it to the DPR
only if it's not in the .DPR directory

it's part of the system.pas which you can't compile so you can't switch it off
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GTDGuyAuthor Commented:
>>it's part of the system.pas
Doesn't make sense that IDE code is in system.pas What code are you talking about so I can review it even if compiling is obviously not possible.
0
 
ziolkoCommented:
there's no way to stop adding units to uses clausule when you plac component of form.
if you want to see.manage dependencies between units check this: http://www.peganza.com/#ICARUS
also GExperts has "Project Dependencies" tool

ziolko.
0
 
ziolkoCommented:
(...)component on form(...)

ziolko.
0
 
Geert GruwezOracle dbaCommented:
look for UnitEntryTable and PackageInfoTable

the source code of system.pas can not be posted here as it is copyrighted
0
 
mikelittlewoodCommented:
There used to be a good PAQ here on how to strip down units from an exe that are not really required but Delphi sticks in anyway. The Sherlock Holmes side to me can't seem to find it though I'm afraid, but it must be around somewhere.
0
 
Geert GruwezOracle dbaCommented:
it is very difficult if you consider subclassing
maybe this is the reason it is not provided
0
 
GTDGuyAuthor Commented:
Sorry this is not what I'm looking for. To further clarify the first issue.

1)Create a new project with default unit and save it. DPR uses should look something like this:

uses
  Forms,
   Unit1 in 'Unit1.pas' {Form1};

2) Now add a conditional like this:
uses
  Forms,
  // or even a plain comment
  {$ifdef IncludeDebug}
  DBMonitor,
  Logger,
  {$endif}
  Unit1 in 'Unit1.pas' {Form1};

3) Now add a second unit and save it (to folder different from DPRs for maximum effect) and then look at what the IDE does to your uses clause. Depends on version of Delphi as to exactly what happens but it is never desired. Especially when the unit does not need to be part of the DPR anyway.

Currently I have to use my version control system to revert my DPRs anytime I add a unit which is frequently. I was just hoping there was a known way to prevent this.

The second issue, adding of unneeded units is a similar annoyance. I use tools such as Lattix for dependency analysis and the included units create annoying false positives.
0
 
GTDGuyAuthor Commented:
>>look for UnitEntryTable and PackageInfoTable
Ok now system.pas makes sense in that you were only referring to the data structures and not to the IDE code that uses them. I was looking more for something like an event in the IDE's open tools api that would allow me to intercept/disable the "updateUsesClause" method in the IDE. Looks like such a delegate does not exist. Also thought about capturing uses before save and restoring in afterwards, but that just creates the need for another save so that becomes circular. I guess there is no current solution to my issues as you mentioned in your first comment.

0
 
ziolkoCommented:
if you have some units that you don't want to be included in .dpr don't add them to project only set path to folder containing it in project -> options ->directories -> search path

>>Now add a second unit and save it (to folder different from DPRs for maximum effect)
don't really know what you mean "maximum effect" if unit is used anywhere in your project it will be compiled and linked into exe and it doesn't matter in which folder it is or is it added directly to .dpr or found thru "search path setting"

ziolko.
0
 
GTDGuyAuthor Commented:
>>add a second unit
Sorry, this should have been clearer. When I said add, I meant create a new unit via the IDE not the inclusion of a preexisting unit. I'm talking about how the IDE automatically adds the newly created unit to a project's DPR uses clause, whether or not it is actually needs to be there and how it destructively removes the existing structure of the DPR's uses clause when it does so.
0
 
ziolkoCommented:
yup, when you go to File -> New -> Unit new unit will be automatically added and .dpr will be changed. that's the way it is you can't avoid it.
only way around it is to have econd instance of delphi opened, create new unit there and save then add search path in "main" project to new unit

ziolko.
0
 
GTDGuyAuthor Commented:
This is my first actual question to Experts Exchange so please forgive me if I don't do thing in quite the proper manner.
 Been think about things and no one really came up with a "solution" to either question. In the future I'll make sure to split questions up. That said, there was enough discussion about it that I think I've come up with a work around for the first one. I will write a plug in for the IDE  that replaces the standard new unit call and does what I want. I think I can close the question as self-solved and still award some points to those whose comments helped in the process. I will attempt to do that now.

Wish to thank everyone for there efforts.
Greg
0
 
Geert GruwezOracle dbaCommented:
Delphi is a great tool,
but all great things come with some smaller things (bugs)

just to help you on the way with OTA :
http://www.tempest-sw.com/opentools/

0
 
GTDGuyAuthor Commented:
Thanks for the link, but I'm not unfamiliar with OTA. I even mentioned that in my initial question but mistyped it as OTI which I do on occasion. Loosing codeRush caused a sudden deep interest in it. ;-) I have a bunch of stuff in D2K7 which I'll move to D2K9 as soon as I finish a current hot project. I will write the plug in at that time as well.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now