Is Key Pressed

A Delphi function to determine if a key on the keyboard is being held down by the user.

Using IsKeyDown:


VK: The virtual key code of the key you want to check.

Return Value:

Returns True if the key specified is pressed, False if the key in not pressed.


Delphi Spell Check

If you are looking for a free Delphi spell checking component for use in your windows applications, you cannot do much better that HunSpell.

HunSpell is a free spell checker that is used by many high profile open source projects, such as OpenOffice.

It is distributed in the form of a Windows DLL that you can ship alongside your application, and also has a great number of dictionaries for various languages.

Where To Start?

Many users downloading the Delphi code from the HunSpell page above will encounter a few problems. Firstly the code does not work with multibyte strings (Delphi 2009+), and the source code samples given depend on a Delphi project that is no longer supported to get working. There are also a couple of bugs in the code provided.

The zip file downloadable below contains all that is needed to implement spell checking in your Delphi applications.

Getting HunSpell Working:

The code in the zip file provided contains the British English dictionaries (if you need other dictionaries, check the links above), the HunSpell DLL, and a fully working non-visual component that can be installed on your component pallet, and included in your applications.

You should install the TSpellCheck component, this component has three properties:

AffFileName: The .aff file with the dictionary you wish to use.

DictFileName: The .dic file with the dictionary you wish to use.

Active: This must be set to True for the component to connect to the HunSpell DLL, and load the dictionary specified.

Creating The Spell Check Component In Code:

If the control is not setup at design time, you can setup the component in code as follows:

 Spell Checking & Suggestions:

You now have a component setup that will allow you to spell check words, and request suggestions as below:

Spell Check Dialog Box

Spell Check


The zip file below also includes a demo project to get you started, play around with it a bit…

If you want to add live spelling, also checkout the Live Spell TEdit control that can be used with this component.

Download Free Delphi Spell Checker:

Live Spell Check TEdit

Delphi edit control that implements live spelling functionality. This control is not tied to a specific spell checking component or library, instead publishes an event to determine if a word is misspelled.

Live Spell Check TEdit

A Delphi TEdit Control with Live Spell Check Functionality

Using Delphi Live Spell Edit:

After downloading and installing the control into a Delphi package, you will find a new control TSpellCheckEdit on your tool pallet under the Controls section.

Adding this control to a form, you will notice a new event on the Object Inspector “OnIsMisspelled” – double click on this to assign a new procedure to this event:

You can see that this procedure has three parameters:

Sender: This will identify the control that called the event

AWord: The word that is to be checked against your dictionary.

IsMisspelled: Setting this value to True will tell the control that the word is correct, and will remove any red underline. Setting this Value to False will add red underlines to the misspelled word.

Right Click Menu Suggestions:

Although this control will not handle suggestions on the right click menu itself, it does implement a few methods and property that make this task easy.

  1. Ensure that the RightClickMoveCaret property is set to True. (this will ensure the selection changes when the user right clicks)
  2. On your TPopupMenu’s OnPopup event handler, use the GetWordAtCaret function to determine the clicked word, and add menu items containing your suggestions to the popup menu.
  3. In your MenuItems onclick event, use the ReplaceWordAtCaret function to replace the current word with the correction.

Download Live Spell Edit:

Download A File From The Web (HTTP)

A simple Delphi function that will download the contents of a file into a TStream over HTTP, useful for downloading web pages and files from the internet.

Using HTTPDownload:


URL: A string value containing the location of the file that is to be downloaded.

AStream: Any descendant of TStream, that will capture the data downloaded.

Return Value:

This function will return the Boolean value if successful.

If the function fails, it will return the Boolean value False.



Calculate Distance Between Longitude and Latitude

A Delphi function that will calculate the distance (as the crow flies) between two longitude / latitude points.

Using DistanceBetweenLonLat:


Lat1: A floating point value containing the latitude part of the first point.

Lon1: A floating point value containing the longitude part of the first point.

Lat2: A floating point value containing the latitude part of the second point.

Lon2: A floating point value containing the longitude part of the second point.

Return Value:

The function will return a floating point value, representing the distance in miles between the two points specified.



Is String An Anagram?

A Delphi function that determines if a group of letters contain an anagram of specified text.


Using IsAnagram:

This function was written to locate words from a dictionary, that could be used in a simple anagram word game. Given a series of letters, the function would test each word from the dictionary one at a time to determine if that word could be a valid anagram made up from those letters.


Letters: A string value containing the letters to be used in the anagram. (Think scrabble tiles)

Text: The text to be checked against letters. (The word to be played in scrabble)

Exact: Are we searching for a perfect anagram, or a partial one? (ie, some tiles left over)

Return Value:

If Exact is True, the function will return True if both Letters and Text are a perfect anagram.

If Exact is False, the function will return True if Text can be made using all or some of the characters in Letters.