ActiveXperts SMS Component


Delphi sample - Send SMS text through an HTTP provider

The ActiveXperts SMS Component is a software development kit (SDK) to enhance an application or script with SMS or Pager functionality. SMS messages can be sent/received using a GSM modem, an SMPP provider or an HTTP compliant SMSC.


In this example we are going to create a Delphi console application project named 'httpsend.dpr' to send SMS messages. This demo project will ask the user to give a phone number and a message body on the command prompt.

A subscription to an HTTP provider is required. For this demo you can send a limited number of messages through our own gateway.

Step 1: Download and install the ActiveXperts SMS Component

Download the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Delphi Project

Launch Delphi from the Start menu. Choose 'New' from the 'File' menu and select: 'Console Application'.

Delphi Pascal

(Click on the picture to enlarge)

Step 3: Refer to the ActiveXperts SMS Component Library and create the objects

Now that a new project has been created, you must add a reference to the ActiveXperts SMS Component in the project to be able to use the ActiveXperts SMS Component objects. To do so, choose 'Import Component...' from the 'Component' menu. The Import Components' dialog appears. Select 'Import a Type Library':

Delphi Pascal

(Click on the picture to enlarge)

In the 'Registered Type Libraries' page, select ActiveXperts SMS Component Type Library' and click 'Next':


(Click on the picture to enlarge)

In the 'Components' page, leave all fields default and click 'Next':


(Click on the picture to enlarge)

In the 'Install' page, select 'Create Unit' and click 'Next':

Borland Delphi

(Click on the picture to enlarge)

The interface code is generated now and is shown in the AxSms_TLB tab of the project.

Step 4: Declare and create the object

From the Project Manager, open Unit1.bas and add the AxSms_TLB to the 'Uses' statement to refer to the ActiveXperts SMS Component library:

Borland Delphi

(Click on the picture to enlarge)

In the 'private' or 'public' section, declare the following objects:

objHttp      : Http;
objConstants : Constants;
objOleVariant: OleVariant;
objSmsMessage: Message;

You can now create the objects, for instance in the 'FormCreate' function:

objHttp       := CoHttp.Create;
objConstants  := CoSmsConstants.Create;
objSmsMessage := coSmsMessage.Create;

Step 5: Send SMS messages

The following code shows how to send an SMS message using the data that was stored in the 'objSmsMessage' and 'objSmsConstants' objects.

strResult := objHttp.SendSms(objOleVariant, objConstants.MULTIPART_OK);

Appendix: Full source code

Following you can find the full source code which is also included in the ActiveXperts SMS Component package.

program httpsend;


  SysUtils, registry, ActiveX, Windows,
  AxSms_TLB in '..\typelib-imports\AxSms_TLB.pas';

 objHttp: Http;
 objConstants: SmsConstants;
 objOleVariant: OleVariant;
 objSmsMessage: SmsMessage;
 strTempUsername: String;
 strTempPassword: String;
 strUsername: WideString;
 strPassword: WideString;
 strToAddress: WideString;
 strBody: WideString;
 strResult: WideString;
 strLogPath: string;
 arrTempPath: array[0..MAX_PATH] of Char;
 objReg: TRegistry;
 strInstallRoot: String;
 objFile: TextFile;

  objHttp := CoHttp.Create;
  objConstants := CoSmsConstants.Create;
  objSmsMessage := coSmsMessage.Create;
  objReg := TRegistry.Create;

  // Display version information about the ActiveXperts SMS Component
  Writeln('SMS Component Version ' + objHttp.Version +
    '; Build ' + objHttp.Build + '; Module ' + objHttp.Module);

  // Set a log file. This will log all communication with the GSM device
  GetTempPath(MAX_PATH, arrTempPath);
  strLogPath := StrPas(arrTempPath);
  strLogPath := strLogPath + 'gsmsend.log';
  objHttp.LogFile := strLogPath;
  Writeln('Log file set to: ' + strLogPath);

  // Get Install Root from registry
  objReg.RootKey := HKEY_LOCAL_MACHINE;
  if (objReg.OpenKey('SOFTWARE\ActiveXperts\SMS Component', False) = False) then
      strInstallRoot := objReg.ReadString('InstallRoot');

  // Read Username and Password from file
  AssignFile(objFile, strInstallRoot + '\Utilities\activexperts-labs.txt');
    ReadLn(objFile, strTempUsername);
    ReadLn(objFile, strTempPassword);
    writeln('Warning, could not find the ActiveXperts Demo Gateway credentials.');

  // Get SystemId
  Writeln('Enter account systemID: (press enter to use ' + strTempUsername + ')');
  if (strUsername = '') then
    strUsername := strTempUsername;

  // Get Password
  Writeln('Enter account password: (press enter to use ' + strTempPassword + ')');
  if (strPassword = '') then
    strPassword := strTempPassword;

  // Set ProviderHost
  objHttp.Url := '' +
    '?username=' + strUsername +
    '&password=' + strPassword +
    '&text=' + objConstants.HTTP_PLACEHOLDER_BODY +
    '&to=' + objConstants.HTTP_PLACEHOLDER_TOADDRESS;

  // Get Recipient
  Writeln('Enter recipient address:');

  // Get Body
  Writeln('Enter the message');

  // Sms Message Properties
  objSmsMessage.BodyFormat := objConstants.GSM_MESSAGEFORMAT_TEXT;
  objSmsMessage.ToAddress := strToAddress;
  objSmsMessage.Body := strBody;

  objOleVariant := OleVariant(objSmsMessage);
  strResult := objHttp.SendSms(objOleVariant, objConstants.MULTIPART_OK);

    // Show error if we could not open the device
  if (objHttp.LastError <> 0) then
      Writeln('Unable to send message: ' +
      Writeln('Press ENTER to close the program');
      Writeln('Result: ' + IntToStr(objHttp.LastError) + ' (' +
        objHttp.GetErrorDescription(objHttp.LastError) + ')');
      Writeln('Response: ' + IntToStr(objHttp.LastResponseCode));

  // Close the device and exit to the command prompt
  Writeln('Press ENTER to close the program');

You can download the full source code of this project from the ActiveXperts FTP site: There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts SMS Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.