3

Just upgraded from Delphi XE to Tokyo, and was hoping for some updated IDE features.

One nice to have feature would be automatically providing options to add a unit to the uses clause. For example, if you reference something in code that isn't in a uses, it would be nice if the IDE prompted you to add the related unit(s).

For example, keeping it simple, in IntelliJ, you might declare a Button, but not yet have added the associated Library to the Import clause.

For Example IntelliJ/Android Studio

When this happens, the offending line is highlighted (just like in Delphi), but the IDE will let you add the necessary library with an Alt-Enter. If there are multiple libraries (it knows about it) it will prompt you for the one you want.

Anything like this for Delphi?

sse
  • 987
  • 1
  • 11
  • 30
  • I guess the problem is that the IDE does not really know anything about code that is not in the `uses`. There is no offline database the IDE could use to find such an identifier and the unit it is in. I assume someone could generate such a database and write a nice expert for it, but I don't know of any yet. – Rudy Velthuis Aug 25 '17 at 22:27
  • The [help/on-topic] says *Questions asking us to **recommend or find a book, tool, software library, tutorial or other off-site resource** are off-topic for Stack Overflow as they tend to attract opinionated answers and spam*. IOW, you can't ask about third-party plugins or components here. You *may* be able to ask at [softwarerecs.se], but be sure and read their guidelines before posting - they're pretty strict about what they allow. If you have a feature you'd like to see in the IDE, ask Embarcadero. – Ken White Aug 25 '17 at 23:03
  • @Rudy, sure a library of known types would be nice, these could be gleaned from the units available in the library path. This is probably how intelliJ does it. For other types, eg, locally defined ones these could be gleaned from the project code/available paths. – sse Aug 25 '17 at 23:05
  • @KenWhite: ISTM he is asking if Delphi can do the same, somehow (some option that must be set). That looks like a valid question to me. – Rudy Velthuis Aug 25 '17 at 23:24
  • @Rudy: If you'll look, I answered the question about the IDE below. I was mentioning what the [help] says for future reference (and because it should be edited out of this post). I'm aware of how the site works, thanks, – Ken White Aug 25 '17 at 23:26
  • @KenWhite: I never implied you didn't know how the site works, just that your comment implied you interpreted the question differently than I did (i.e. that he was asking for a 3rd party tool). – Rudy Velthuis Aug 25 '17 at 23:37
  • @Rudy: The single question asked in the post (as written - see the history - which I commented to) asked for a third-party tool. The edited version asks *Anything like this in Delphi?*, which is perfectly appropriate here. Advice on what is and isn't proper to ask here is also entirely appropriate, if the poster does not appear to be aware. – Ken White Aug 25 '17 at 23:42
  • I just looked at the history. He did not just ask for a 3rd party tool. He asked, as I see it: "I know this IDE, IntelliJ, that has this nice feature. Does Delphi have a similar feature, and if not, is there a plugin that can provide it?". I think that is valid. – Rudy Velthuis Aug 25 '17 at 23:55
  • @Rudy: I don't know what you're nattering on about here. I did not downvote the question, I did not close vote the question, I answered the question. I advised the poster that asking for off-site resources isn't acceptable (which is what *is there a plugin that can provide it* asks), and linked to the [help/on-topic] that says so. The poster was considerate enough to edit out the off-topic portion himself, so the only one who seems obsessed with the issue is you. If you take issue with the way the [help/on-topic] guidelines are defined or written, please take that issue up at [meta]. Thanks. – Ken White Aug 26 '17 at 01:44

1 Answers1

7

Delphi 2007 and later versions support this for most types that it knows about (in the search or library path). (It may have been available in D2005/2006; I don't have them installed anywhere now to check. I know it was not in Delphi 7.)

Put in the type, and use the Refactor menu (Refactor->Find Unit) or press Ctrl+Shift+A.

Here's an example:

![Find unit dialog

It's not 100% effective, but it's a vast improvement over the old way.

(And yes, I know about TArray<string>, before someone chimes in. I just grabbed a quick type that I knew wouldn't be in the default VCL form uses clause for an example.)

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Does it also find identifiers that are not in a unit in the uses clause? I just tried with a console app, and I couldn't find TButton. I could find identifiers that were in the uses clause. But perhaps I didn't do things right? The VCL is in the library path, AFAIK. – Rudy Velthuis Aug 25 '17 at 23:31
  • @Rudy: I don't know exactly what it will or won't search. It found `System.Types` in the example I used, which is not in the `uses` clause. All I have is [the documentation](http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Find_Unit) and a blog post somewhere (can't recall offhand where, but I'll try to find it). – Ken White Aug 25 '17 at 23:35
  • @Rudy: Actually, [Berlin docs](http://docwiki.embarcadero.com/RADStudio/Berlin/en/Finding_Units_(Delphi)) have a somewhat better description, but it's still not highly informative about where it will look. – Ken White Aug 25 '17 at 23:39
  • AFAIK, it only looks in units (directly?) used in the current project. I tried in a DUnit project, and it still did not find TButton, although I am sure the project has buttons. – Rudy Velthuis Aug 25 '17 at 23:44
  • @Rudy: Clearly not, as `System.Types` is **not** used in the example I posted (see the image, which very intentionally included the `uses` clause to demonstrate that fact - you can see both the `interface` and `implementation` sections, and there's no `System.Types` in either of them), and my final paragraph indicates why I chose `TStringDynArray` as the type (because I knew `System.Types` was not in the default units). – Ken White Aug 25 '17 at 23:46
  • Hmmm... the project has a toolbar and it could indeed find TToolBar in Vcl.ComCtrls. System.Types is probably used indirectly, i.e. by one of the other units in the project. – Rudy Velthuis Aug 25 '17 at 23:48
  • @Rudy: I can't explain what the functionality does. The poster asked if something existed in the IDE, and I pointed out that it did. How it works (or how well) is something I can't really address. I can just say it's there. – Ken White Aug 26 '17 at 01:35
  • 1
    Hasn't that functionality been part oft the IDE since, like forever? It certainly is available in Delphi 2007 (And wasn't there in Delphi 7.) – dummzeuch Aug 26 '17 at 08:25
  • @dummzeuch: Yeah, it's been around a while. I just couldn't say for certain when it was added, as I only have Seattle and up on this machine. I was going to check D2007 and one of the XE versions when I go to work on Monday and edit then. – Ken White Aug 26 '17 at 14:44