Postal Code Lookup

Morfik's Placename Lookup Package provides the interface to the Web Service that returns a list of places for a given postal code.


A Quick Walkthrough

To use Morfik's Placename Lookup Package, add the package to the project by using the ‘Used Packages’ command on the project ribbon (see Figure 1), or drag the package file onto the application main client area.

Figure 1: Used Packages Command

To use it in your code, first you have to add mfk_pcMain to the ‘Uses’ section of your module. Then you can use the TPostalCodeInfo class like this:

FX Code

    PostalCodeInfo := TPostalCodeInfo.Create;
    PostalCodeInfo.Country := 'US';
    PostalCodeInfo.PostalCode := '94109';
    PostalCodeInfo.Callback   := GetMethodPointer(Self, @HandlePostalCode);
Procedure HandlePostalCode(CompletedAddresses : TArray);
    i : Integer;
    Place : TPlace;
    For i := 0 To CompletedAddresses.Count - 1 Do
        Place := CompletedAddresses[i];
        ComboBox1.Add(Place.countryCode +'  '+ Place.postalcode +'  '+ Place.placeName);

The code above will put one item into the combobox: “San Francisco”. If the same postal code is being used for several locations, the CompletedAddresses array contains more than one item.

If no information is available or the postal code is incorrect empty array is returned.

Note: Execute is an asynchronous method; it returns immediately. When the location information is retrieved the callback you provided gets called.
Note: Country is the country code according to ISO 3166. Please refer to for the complete list of country codes.

See Also

Back to top