Link to home
Start Free TrialLog in
Avatar of GTDGuy
GTDGuy

asked on

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.
Avatar of Geert G
Geert G
Flag of Belgium image

nope
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.
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
Avatar of GTDGuy
GTDGuy

ASKER

>>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.
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.
(...)component on form(...)

ziolko.
SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
it is very difficult if you consider subclassing
maybe this is the reason it is not provided
Avatar of GTDGuy

ASKER

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.
Avatar of GTDGuy

ASKER

>>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.

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.
Avatar of GTDGuy

ASKER

>>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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/

Avatar of GTDGuy

ASKER

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.