Source Code Tools

Use the Source!

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.

Source Folder 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.

Source Folder

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.

control.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.

Indexing Options

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

Indexing File Types

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.

Indexed Locations - Source

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.

Search Results

Everything Search

Everything Software IconAnother 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.

Everything Search

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.

What else do you use the source for?

4 replies on “Use the Source!”

A few notes about Windows search:
Windows search has been available since Windows XP where it was initially known as Windows Desktop Search. So the mentioned functionality can be used on any Windows versions since Windows XP forward.
After changing the indexing settings so that it indexes contents of the source files you don’t need to wait before you start searching in your source code. You can go straight into the folder containing your source files and start searching. it will just take a bit of time before your first search results are returned. Note if you wait for indexer to finish indexing all the new files on its own it will take much more time since file content indexing is considered as low priority and therefore is usually done during computer inactivity.
Also you don’t necessarily have to ad your source code folder to indexing list and still search the source files for certain text. It will be just slower because Windows Search would have to check all of the source files at that time and won’t save indexing results for future searches. Due to same reasons you will be able to practically search contents of every source file in any folder and its subfolder if the search has been done from that folder. Exceptions are network mapped folders which by default can’t be searched this way unless you mark them to be synchronized.

And now a word of caution:
While Windows Search can be very powerful toll for searching data within files (especially if they are indexed) it could also potentially be a security risk.
In the past I have experienced scenario when Windows Indexing Service tried to send some data to one of the Microsoft servers just after I have added a new folder to indexing list. So taking into account what information Microsoft is gathering about us lately I wouldn’t be surprised if list of all indexed words and perhaps filenames in which the are found would be sent to Microsoft.
Also do note that Windows Search API is available to other programs on your computer (at least it was a few years ago) since such programs can then find out which of your files contains certain content and then proceed downloading them. Not to mention that in the past I have seen Windows Search index contents of a password protected word document as if there would be no password protection on it.
So in short I don’t trust Microsoft any more and thus I won’t enable Windows Search to index any of the source files on my computer. And if the need for finding some function in all of my source files arises I can quickly modify my Word compression algorithm to spit out the needed results since this algorithm is during its execution basically generating the same list of indexed words as Windows Search does.

Comments are closed.