17

MS Visual Studio has a great feature: it automatically suggests the units to add in using clause when you typing the code with refrences to absent standard classes.

Is there any 3-rd party tool to implement similar feature for Delphi?

I'm tired to add all those SysUtils, Windows, Messages etc in each new unit.

Andrew
  • 3,696
  • 3
  • 40
  • 71
  • 7
    +1 That's a great feature in VS that is sorely lacking in RAD Studio – David Heffernan Feb 23 '12 at 09:03
  • +1 what David said + it shouldn't be too complicated to parse all units from "paths" and store them in a sqlite db or something light so that when you press CTRL+SPACE and type something that's not related to units already included, it should show options like "declare type|class|etc." or "include unit X" if it finds what you're typing... –  Feb 23 '12 at 09:21
  • When you use code completion the unit will be added when it's not already there. So it is possible. – The_Fox Feb 23 '12 at 09:26
  • 3
    in Win7 (and may be Vista) you can add *.pas files to indexing in Control Panel.. so after typing for exmaple `WM_CLOSE` in start menu search string you will get some results.. of course it's not tool for delphi.. but it is handy to find needed units; see screenshot: http://img204.imageshack.us/img204/7278/123qav.png – teran Feb 23 '12 at 09:37

6 Answers6

12

If the unit which contains the reference is not yet in the uses list, this is how I save many manual steps:

  • right-click on the underlined (error-insighted) text
  • choose “Refactoring | Find Unit…“.

A dialog will present the available unit which contains the unknown type or symbol, and a mouse click adds the selected unit to the uses list of the current file.

mjn
  • 36,362
  • 28
  • 176
  • 378
  • 1
    Can I change/extend the browsing paths? – Andrew Feb 23 '12 at 13:12
  • This blows up with out of memory in XE5 Update 2 :-( My method for RTL functions: press F1 on the identifier and copy & paste the unit they are in. – boggy Feb 27 '14 at 19:55
  • Doesn't always work: will not find Winapi.MMSystem for PlaySound function. –  Jun 05 '16 at 09:13
3

The JCL includes the "Uses Wizard." It watches for compilation errors mentioning "Undeclared identifier," and when it sees one, it automatically adds the unit where that identifier is declared.

The package JclUsesExpert.dpk is only available for certain Delphi versions. I don't know if that's because the plug-in doesn't work in later versions, or if someone merely neglected to copy the project into later versions' folders.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
2

CNPack Input Helper can sugest and autocomplete units (sorry for another answer, but I can't comment other).

CNPack unfortunately don't auto-add units from place of code input but you can:

  • Copy a word from cursor place (CNPack->Editor enchancements->Tabset/Button->Clipboard operations->Cut/copy token...).
  • Eventually search this word in source files (grep) to identify unit.
  • Use CNPack->Toggle Uses/Include Field (Ctrl+u) and start typing and use CNPack->Input Helper sugestion/autocompletion, or IDE/GExperts/CNPack use unit future
  • Back to place of code edition
g2mk
  • 509
  • 3
  • 13
  • I can't understand how to use this Input Helper for suggestion which units to include into `uses` clause. Can you explain your scenario? – Andrew Feb 23 '12 at 12:18
1

This is not a tool to suggest references, it only cleans up unneeded unit clauses.

CnPack IDE Wizards is an excellent opensource plugin for Delphi.
http://www.cnpack.org/index.php?lang=en

I use its Uses cleaner feature a lot. There is a menu item:
CnPack->Project Enhancements->Use Unit

I think this can be helpful for your needs.

Johan
  • 74,508
  • 24
  • 191
  • 319
hubalazs
  • 448
  • 4
  • 13
  • nope. it can help in managing existed references, but cannot suggest references. – Andrew Feb 23 '12 at 09:19
  • 1
    @hubalu, but this question is about unit suggestion. When you type for instance `ShellExecute` then you'll get `ShellAPI` unit suggested. – TLama Feb 23 '12 at 09:20
0

The rFindUnit IDE extension is the enhanced version of built-in "Refactoring | Find Unit…" function suggested by @mjn above.

Edwin Yip
  • 4,089
  • 4
  • 40
  • 86
0

Or maybe you can try this: http://www.epocalipse.com/products.htm

Unit Expert

"A freeware Delphi add-in that allows you to quickly open units and also add them to the uses clause."

I never tried this expert but it semms promising.

hubalazs
  • 448
  • 4
  • 13