Solved

Anyway to prevent Delphi from automatically touching uses clauses

Posted on 2008-10-01
18
373 Views
Last Modified: 2013-11-23
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
Comment
Question by:GTDGuy
  • 6
  • 5
  • 4
  • +1
18 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 22613508
nope
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22613760
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 22614045
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
 

Author Comment

by:GTDGuy
ID: 22615213
>>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
 
LVL 21

Expert Comment

by:ziolko
ID: 22616305
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
 
LVL 21

Expert Comment

by:ziolko
ID: 22616310
(...)component on form(...)

ziolko.
0
 
LVL 36

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 100 total points
ID: 22621826
look for UnitEntryTable and PackageInfoTable

the source code of system.pas can not be posted here as it is copyrighted
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22624642
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 22624706
it is very difficult if you consider subclassing
maybe this is the reason it is not provided
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22624715
0
 

Author Comment

by:GTDGuy
ID: 22630666
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
 

Author Comment

by:GTDGuy
ID: 22630730
>>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
 
LVL 21

Expert Comment

by:ziolko
ID: 22631287
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
 

Author Comment

by:GTDGuy
ID: 22639413
>>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
 
LVL 21

Assisted Solution

by:ziolko
ziolko earned 100 total points
ID: 22639785
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
 

Accepted Solution

by:
GTDGuy earned 0 total points
ID: 22675602
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 22676796
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
 

Author Comment

by:GTDGuy
ID: 22677171
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now