One of the great things about Delphi is not only is it written in Delphi (mostly), but it ships with the VCL, RTL, & FMX source code. You can use this source code in lots of different ways, which I’ll cover in a bit, but sometimes it is a matter of finding the source file with the code you want. There are over 2,234 Delphi source files in the source folder, so it can take a while to find the right file if you don’t know where to look. Not to mention the 1,711 C files, and a few thousand other assorted files.
I used to use various GREP and full text searching tools to find the code I was looking for, but then I realized Windows 10 (and earlier versions) has a search function built into it, but you need to make a few configuration changes to use it effectively. So I thought I would outline those for you.
Your source folder is usually located in
C:\Program Files (x86)\Embarcadero\Studio\19.0
but it might be different depending on your installation. I usually Pin it to Quick Access, which makes it easy to access since I find I’m there a lot.
Windows Search and Indexing Options
The next thing to do is configure your Indexing Options. This is what makes it quick to search for files you need. You can find Indexing Options in Control Panel, or just runcontrol.exe srchadmin.dll.
There are two steps to get the most out of Windows search for your source code. The first is you need to activate Windows search for the file extensions you want, and the second it to tell it to index your folders.
To add PAS files to indexing click Advanced and go to File Types. You can just type PAS in the list of file types and it will find it for you. You don’t need to add a new extension. PAS files are already listed, but just not indexed by default. Just put a check next to it, and change the “How should this file be indexed?” to “Index Properties and File Contents” that will index all the text contents of the file
By default all your user folders are indexed, but Source is in your Program Files folder, so you need to explicitly add it. From the main Indexing Options window click Modify and from there you can add any folder you want to search.
It takes a while a while to build and update the index after this change. You just gave it 2,000 more files to index. It has to read all the text out of them, which takes a while. Once it is done then just go to your source folder and use the search box to quickly find the code you are looking for.
Everything Search
Another great tool to use, to search by file name is the Everything desktop search engine by Voidtools. The thing I love about using Everything is it searches all the file names on your system quickly. The difference between it and Windows Search is Everything only searches the file names, but it searches all the file names.
I find I usually remember the name of a file, but not exactly where I left it. This makes Everything indispensable for me.
Using the Source
So how useful is it that Delphi, RAD Studio and C++Builder includes all this source code? What all can you do with it?
- Finding that function – You know how I said I can remember the name of a file, but not where I put it? I do the same things with classes and functions. I can remember the name of the method or class, but not which unit it is in. Being able to search all of the source instantaneously to find the source file you need is a huge help.
- Learning – Just reading source isn’t the best way to learn to program, but having access to the source code is a great way to gain a deeper understanding.
- Debugging – Sometimes your program doesn’t behave the way you expect it to. When all you have is a blackbox then you are unable to figure out what is happening behind the scenes. When you have the source code you can not only see how that method is implemented, but also debug into the source code, using all the great debugger features.
- Adding New Features – Maybe there is a new API that was just released, or you need to access an obscure API or 3rd party feature. Since you have access to all the source you can see how other similar APIs are accessed and use that as a roadmap.
- Fixing or Changing Functionality – One man’s bug is another man’s feature. Sometimes there are bugs you need to fix in the shipping source code, other times you just want to change the way things work. For small changes I just copy the source file out into my project directory. Then my code will use my modifications instead of the original implementation. While you can’t redistribute changed source code, you can compile the code into your program. If you do need to share your changes or fixes you can share a change-set that only contains your changes.