HOME - - - - - - - TUTORIALS INDEX - - - - - - - - - - - - Other material for programmers

Delphi: A Word Search Program



Tutorial written and tested in Delphi 2, on a Win98 machine, but the code should be pretty generally applicable. You can download the sourcecode and some other stuff.

This program was written to illustrate some points of Delphi programming. There are areas where severe shortcuts have been taken, e.g. the lack of flexibility over where the output files go, and their names.

The program is not meant to be "finished", or "good"... but it does work, and parts of it are well made. The rest are started in a manner which does not obstruct eventual fine tuning.

The program asks the user for a set of letters, and then generates all possible combinations of those letters, sorting the resulting "words" into separate files, depending on the likelihood of that string of letters is used as a word in English.

I wrote the program with this tutorial half in mind, but inspired by a wish to pull a friend's leg over the assertion in Dan Brown's "Da Vinci Code" that there are 92 words in "planets". With a version of this program, I found all of them... but my list included about 11,000 others, too!


This might be a good time to download the sourcecode. If you click on that link, you will receive an .exe file which will let you fill the folder of your choice with the necessary files, and does nothing more than put some files in the folder you spoecify. Unusually for my archives, one of the included files is an exe file. Run it to see the word seach program in action. Alternatively, you can download a simpler, .zip archive version.

I will take you through some of the features from the user's point of view. Then, here, and in the sourcecode, you will find notes on how those features were implemented.

The program comes to life with an edit box, a "Go" button, a memo for showing how things are going, and a "Quit" button. The edit box has "fish" in it, as a default starting point.

Click "Go" and you'll see permutations of the letters in "fish" appear in the memo box. At the same time, the permutations are being written to output files named DD43R0.txt - DD43R5.txt (Delphi Demo 43 Results, level 0 - 5). The words in DD43R0.txt are known to be real English words. The program's capability to recognize real words is severely degraded in the version I've put in the zip. If you look online for "two letter words" scrabble, you will find various lists of dubious or clear copyright status. Look in the sourcecode for "qTwo" to learn about restoring the dictionary search capability of the program.

If you modify the word in the edit box, you can check the permutations of other sets of letters. Not that if you shorten the word to less than three letters, or more than seven letters, the "Go" button is disabled. This is because the program will not work except for 3-7 letter words. (You could extend the program to handle longer words. You just add code at "(*Insert deeper layers HERE*)", and extend the "sCombo:=copy(sCombo,1,5); ClearBoUsed; boUsed[c1]:=true;" stuff you'll find shortly thereafter.) The mechanism for "turning off" the "Go" button is all in the OnChange event for the edit box, eStartWord.

The second time you run the program, the data output during the first running of the program is over-written. This is very clumsy, as is the fact that the datafiles are put in the e program's folder, but this tutorial is not about file handling. The code works, however inelegantly. If you want to save results, use Windows Explorer to move or rename them before re-running the program.

A seven letter word generates about 11,000 permutations. There would be no point in having all of them available in the on-screen memo. Examine the sourcecode for the details of how the memo is used to display just the most recently computed permutations. While the program is running, you can see the progress as the permutations scroll past. Search the sourcecode for "qMemoScroll" for the heart of that feature's implementation.

See the sourcecode for other gems. The several such items are flagged with the comment "qOther".


And there you have it! I hope you found some useful things in the code. If you have a webpage, links to any of my pages would be appreciated.
            powered by FreeFind
  Site search Web search
Site Map    What's New    Search This search merely looks for the words you enter. It won't answer "Where can I download InpOut32?"
The search engine is not intelligent. It merely seeks the words you specify. It will not do anything sensible with "What does the 'could not compile' error mean?" It will just return references to pages with "what", "does", "could", "not".... etc.

Also: This search only searches the material on one of my websites.

      Click here to visit another of my sites.

      Click here to visit my third site.




Click here if you're feeling kind! (Promotes my site via "Top100Borland")
Ad from page's editor: Yes.. I do enjoy compiling these things for you. I hope they are helpful. However... this doesn't pay my bills!!! Sheepdog Software (tm) is supposed to help do that, so if you found this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Link to Tutorials main page
How to email or write this page's editor, Tom Boyd


Valid HTML 4.01 Transitional Page WILL BE tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org


If this page causes a script to run, why? Because of things like Google panels, and the code for the search button. Why do I mention scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....