6

I've been using cnPack and PascalAnalyzer Lite to clean up the uses clauses in some large projects, and I'm doing it rather conservatively. In particular I'm not removing anything that has an initialization section. PascalAnayser gives hints such as

  ==> COMMAND unnecessary (used by unit with init)

I assume this is saying that this unit is not used by the current unit, but it is used by a unit that has an initialization section.

Is this unit COMMAND completely safe to remove or is there some situation where removing it might cause some sort of run-time error?

Alister
  • 6,527
  • 4
  • 46
  • 70
  • If you're asking if removing some code can cause any runtime problems, that is possible - you have to examine the code. If you're asking what exactly that hint means, product support may be more accurate describing it. – Sertac Akyuz Jun 17 '18 at 22:25
  • @SertacAkyuz Removing a unit with an `initialization` section certainly could cause problems, but I'm pretty sure that removing a unit that is used by a unit with an `initialization` section should be safe, but not 100% certain - ignoring any RTTI issues of course, which is what I'm trying to ask - was it not clear? – Alister Jun 17 '18 at 23:06
  • 1
    Actually that seems to be clear. I got sidetracked because I don't understand the same thing from the hint with you. Why would the product care if a unit is used from elsewhere or not while reporting it to be unused in some unit. Anyway, don't mind me, if you ask what I understand from that hint ... nothing. – Sertac Akyuz Jun 17 '18 at 23:32
  • @SertacAkyuz Thanks, there a lot of these hints, and it would be great to remove these unit dependencies, but I'm just being chicken as the projects are huge and it might be hard to tell if removing the units causes any subtle problems. – Alister Jun 17 '18 at 23:40
  • 1
    This [manual page](https://peganza.com/PALHelp/index.html?uses_report.htm) wouldn't be of help? – Victoria Jun 18 '18 at 00:08
  • @Victoria Sadly no, it says I can "probably remove" the unit - doing so certainly doesn't create any compile-time errors - but I'm concerned about run-time errors. Although I'm becoming more convinced that it is safe. – Alister Jun 18 '18 at 02:12
  • 5
    I wonder why such tools can't issue more readable messages. If you must wonder (or look up) what it means, the message is not very useful, IMO. – Rudy Velthuis Jun 18 '18 at 06:58
  • 1
    @Rudy At least they don't use strange 8 letter codes that you have to go to their website and dig for, like one software I use. – Jerry Dodge Jun 18 '18 at 13:27
  • 1
    @Jerry: That sounds terrible, indeed. – Rudy Velthuis Jun 18 '18 at 13:44

1 Answers1

4

You can safely remove that unit.

That hint is just there out of consistency, to give you some more information - although that information is irrelevant to the decision whether that unit can be removed from the uses clause, can be moved to the implementation section or has to stay where it is.

In case you are trying to get rid of that unit, you now know that you have to check that unit with initialization: Does it actually need that unnecessary unit or can it perhaps be removed safely itself?

As you already mentioned: it is just a hint - it doesn't invalidate the unnecessary mark.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • 1
    I still can't make out what that hint is saying. Could you perhaps elaborate. – David Heffernan Jun 18 '18 at 08:49
  • 1
    _used by unit with init_ means that the unit COMMAND is also used by a unit that has an initialization section. As long as this initialization code has to stay in the program, the COMMAND unit is compiled, too. Keeping it in your current uses clause despite not being needed for compilation in this unit will not change anything, so you can safely remove it here. Whether this hint has any value for you depends on your current intentions. – Uwe Raabe Jun 18 '18 at 09:06