REST.SurfSpotFinder Sample (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

This sample shows how to integrate and use REST services in your application by using the Spitcast API in a Delphi application.

Location

You can find the SurfSpotFinderApp sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and navigate to:
    • Object Pascal\Multi-Device Samples\Cloud\SurfSpot Finder
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The application connects to the REST service from Spitcast to retrieve the list of Surf spots (sea locations for surfing). The application creates a main form that has two TMultiView components. Each TMultiView component contains a list of Surf spots and uses the TPanel to display the coordinates and county information, and the location coordinates on a map. Select a Surf spot from the SurfSpot finder list, and its location info is displayed. Click the plus icon to save the selected Surf spot in a text file and add it to the Favorite Spots list.

Note: Public distribution of Spitcast API content must acknowledge Spitcast as the content source, and provide a link to spitcast.com. The Spitcast API is available for non-commercial use. Commercial use is possible by prior arrangement.

How to Use the Sample

  1. Navigate to Start | Programs | Embarcadero RAD Studio Alexandria | Samples and open:
    • Delphi: SurfSpotFinderApp.dproj
  2. Press F9 or choose Run > Run.

Files

This project has one source file, SurfSpots.pas, that is, the main form that contains the REST Client and the TMultiView components.

Classes

TSurfSpotFinder, the form class, implements the main visual component of the application. It contains two TMultiView components and a TPanel with a TWebBrowser component for displaying the location on a map. It also contains the following components: TRESTClient, TRESTResponse, TRESTRequest, and TRESTResponseDataSetAdapter.

Implementation

  • For both TMultiView components, in the Object Inspector set the TargetControl property to Panel1.
  • For the TMultiView1 component, in the Object Inspector set the MasterButton property to backbtn.
  • For the TMultiView2 component, in the Object Inspector set the following properties:
  • For the RESTClient1 component, in the Object Inspector set the BaseURL property to http://api.spitcast.com.
  • For the RESTRequest1 component, in the Object Inspector set the following properties:
    • The Client property to RESTClient1.
    • The Response property to RESTResponse1.
    • The Resource property to api/spot/all.
    • The Method property to rmGET.
    • Right-click the RESTRequest1 component and click Execute.
  • For the RESTResponseDataSetAdapter component, in the Object Inspector set the following properties:
    • The Response property to RESTResponse1.
    • The Dataset property to FDMemTable1.
  • Right-click the FDMemTable and select Fields Editor.
    • Right-click the Fields Editor, select Add Fields and the fields county_name, latitude, longitude, spot_id, and spot_name.
  • For the TMultiView1 component, visually bind the Surf Spots list from the Spitcats API call.
  • The TMultiView2 component displays a list of the Favorites Surf Spots that is saved in a file.

Uses

See Also

Samples