Saving TAdModem Configurations

The TAdModem component provides a large list of modems and many options for configuring and selecting modems.  However, loading and saving the modem configuration is not completely obvious.

The SelectModem method in the TApdModem class is used to select the modem that is used.  By default, this will prompt the user for the manufacturer and model of their modem.  This method can also be used to load the modem configuration without prompting the user.  If the modem manufacturer and name as well as the name of the XML file containing the modem details are specified in the SelectedDevice property before SelectModem is called, SelectModem will load the modem details without prompting the user.

The GetDevConfig and SetDevConfig provide access to the modem configuration (parity, stop bits, and related values).  This information should also be saved with the modem configuration.

The following code shows a simple means of saving the modem selection and configuration to an INI file.  The saving code is pretty straightforward.  It reads the information in the SelectedDevice property and the result of the GetDevConfig method and writes that information to the INIFile.

In Delphi

procedure SaveModemConfiguration (FileName : string;

                                  Modem    : TAdModem);


  INIFile     : TINIFile;

  ModemConfig : TApdModemConfig;


  INIFile := TINIFile.Create (FileName);


    { Save the current modem }

    INIFile.WriteString ('Modem', 'File', Modem.SelectedDevice.ModemFile);

    INIFile.WriteString ('Modem', 'Manufacturer', Modem.SelectedDevice.Manufacturer);

    INIFile.WriteString ('Modem', 'Name', Modem.SelectedDevice.Name);

    { Get the modem configuration }

    ModemConfig := Modem.GetDevConfig;

    { Save the modem configuration }

    INIFile.WriteString ('Settings', 'ComPort', ModemConfig.AttachedTo);

    INIFile.WriteInteger ('Settings', 'DataBits', ModemConfig.DataBits);

    case ModemConfig.Parity of

      pEven  : INIFile.WriteString ('Settings', 'Parity', 'Even');

      pOdd   : INIFile.WriteString ('Settings', 'Parity', 'Odd');

      pMark  : INIFile.WriteString ('Settings', 'Parity', 'Mark');

      pSpace : INIFile.WriteString ('Settings', 'Parity', 'Space');

      pNone  : INIFile.WriteString ('Settings', 'Parity', 'None');


    INIFile.WriteInteger ('Settings', 'StopBits', ModemConfig.StopBits);

    case ModemConfig.SpeakerVolume of

      svLow  : INIFile.WriteString ('Settings', 'SpeakerVolume', 'Low');

      svHigh : INIFile.WriteString ('Settings', 'SpeakerVolume', 'High');

      svMed  : INIFile.WriteString ('Settings', 'SpeakerVolume', 'Med');


    case ModemConfig.SpeakerMode of

      smOff  : INIFile.WriteString ('Settings', 'SpeakerMode', 'Off');

      smOn   : INIFile.WriteString ('Settings', 'SpeakerMode', 'On');

      smDial : INIFile.WriteString ('Settings', 'SpeakerMode', 'Dial');


    case ModemConfig.FlowControl of

      TApdModemFlowControl (fcOff) :

               INIFile.WriteString ('Settings', 'FlowControl', 'Off');

      fcSoft : INIFile.WriteString ('Settings', 'FlowControl', 'Soft');

      fcHard : INIFile.WriteString ('Settings', 'FlowControl', 'Hard');


    if ecOn in ModemConfig.ErrorControl then

      INIFile.WriteBool('Settings', 'ErrorControlOn', True);

    if ecOff in ModemConfig.ErrorControl then

      INIFile.WriteBool('Settings', 'ErrorControlOff', False);

    if ecForced in ModemConfig.ErrorControl then

      INIFile.WriteBool('Settings', 'ErrorControlForced', False);

    if ecCellular in ModemConfig.ErrorControl then

      INIFile.WriteBool('Settings', 'ErrorControlCellular', False);

    INIFile.WriteBool ('Settings', 'Compression', ModemConfig.Compression);

    case ModemConfig.Modulation of

      smBell      : INIFile.WriteString ('Settings', 'Modulation', 'Bell');

      smCCITT_V23 : INIFile.WriteString ('Settings', 'Modulation', 'CCITT_V23');

      smCCITT     : INIFile.WriteString ('Settings', 'Modulation', 'CCITT');


    INIFile.WriteBool ('Settings', 'ToneDial', ModemConfig.ToneDial);

    INIFile.WriteBool ('Settings', 'BlindDial', ModemConfig.BlindDial);

    INIFile.WriteInteger ('Settings', 'CallSetupFailTimeout', ModemConfig.CallSetupFailTimeout);

    INIFile.WriteInteger ('Settings', 'InactivityTimeout', ModemConfig.InactivityTimeout);

    INIFile.WriteString ('Settings', 'ExtraSettings', ModemConfig.ExtraSettings);





For C++ Builder

void __fastcall SaveModemConfiguration (AnsiString  FileName,

                                        TAdModem   *Modem)


  TIniFile        *INIFile;

  TApdModemConfig  ModemConfig;

  // Save the current modem

  INIFile = new TIniFile (FileName);

  INIFile->WriteString ("Modem", "File", Modem->SelectedDevice->ModemFile);

  INIFile->WriteString ("Modem", "Manufacturer", Modem->SelectedDevice->Manufacturer);

  INIFile->WriteString ("Modem", "Name", Modem->SelectedDevice->Name);

  // Get the current modem configuration

  ModemConfig = Modem->GetDevConfig();

  // Save the configuration

  INIFile->WriteString ("Settings", "ComPort", ModemConfig.AttachedTo);

  INIFile->WriteInteger ("Settings", "DataBits", ModemConfig.DataBits);

  switch (ModemConfig.Parity) {

    case pEven  : INIFile->WriteString ("Settings", "Parity", "Even");


    case pOdd   : INIFile->WriteString ("Settings", "Parity", "Odd");


    case pMark  : INIFile->WriteString ("Settings", "Parity", "Mark");


    case pSpace : INIFile->WriteString ("Settings", "Parity", "Space");


    case pNone  : INIFile->WriteString ("Settings", "Parity", "None");



  INIFile->WriteInteger ("Settings", "StopBits", ModemConfig.StopBits);

  switch (ModemConfig.SpeakerVolume) {

    case svLow  : INIFile->WriteString ("Settings", "SpeakerVolume", "Low");


    case svHigh : INIFile->WriteString ("Settings", "SpeakerVolume", "High");


    case svMed  : INIFile->WriteString ("Settings", "SpeakerVolume", "Med");



  switch (ModemConfig.SpeakerMode) {

    case smOff  : INIFile->WriteString ("Settings", "SpeakerMode", "Off");


    case smOn   : INIFile->WriteString ("Settings", "SpeakerMode", "On");


    case smDial : INIFile->WriteString ("Settings", "SpeakerMode", "Dial");



  switch (ModemConfig.FlowControl) {

    case Admdm::fcOff : INIFile->WriteString ("Settings", "FlowControl", "Off");


    case fcSoft :       INIFile->WriteString ("Settings", "FlowControl", "Soft");


    case fcHard :       INIFile->WriteString ("Settings", "FlowControl", "Hard");



  if (ModemConfig.ErrorControl.Contains (ecOn))

    INIFile->WriteBool("Settings", "ErrorControlOn", True);

  if (ModemConfig.ErrorControl.Contains (ecOff))

    INIFile->WriteBool("Settings", "ErrorControlOff", False);

  if (ModemConfig.ErrorControl.Contains (ecForced))

    INIFile->WriteBool("Settings", "ErrorControlForced", False);

  if (ModemConfig.ErrorControl.Contains (ecCellular))

    INIFile->WriteBool("Settings", "ErrorControlCellular", False);

  INIFile->WriteBool ("Settings", "Compression", ModemConfig.Compression);

  switch (ModemConfig.Modulation) {

    case smBell      : INIFile->WriteString ("Settings", "Modulation", "Bell");


    case smCCITT_V23 : INIFile->WriteString ("Settings", "Modulation", "CCITT_V23");


    case smCCITT     : INIFile->WriteString ("Settings", "Modulation", "CCITT");



  INIFile->WriteBool ("Settings", "ToneDial", ModemConfig.ToneDial);

  INIFile->WriteBool ("Settings", "BlindDial", ModemConfig.BlindDial);

  INIFile->WriteInteger ("Settings", "CallSetupFailTimeout", ModemConfig.CallSetupFailTimeout);

  INIFile->WriteInteger ("Settings", "InactivityTimeout", ModemConfig.InactivityTimeout);

  INIFile->WriteString ("Settings", "ExtraSettings", ModemConfig.ExtraSettings);

  delete INIFile;


The following code shows how to load the information saved by SaveModemConfiguration.  This is a bit more involved.  There are several little things that have to be tweaked to get the modem information loaded correctly.

First, the code needs to make sure that the modemcap database is set consistently in the LibModem object in the TApdModem component.  The following line handles this:

Modem.LibModem.LibModemPath := Modem.ModemCapFolder;

Then a dummy modem configuration is set by using the.DefaultDeviceConfig method of the TAdModem component.  The modem line settings (parity, error correction and the like) are loaded and a call to SetDevConfig is used to configure those settings in the AdModem component.

The modem manufacturer, name and modem file is loaded from the INIFile and placed in the SelectedDevice property.  This is enough information to specify the modem; a call to SelectDevice loads the modem information.

The code for Delphi looks like this.

procedure LoadModemConfiguration (FileName : string;

                                  Modem    : TAdModem);


  INIFile     : TINIFile;

  ModemConfig : TApdModemConfig;

  WorkStr     : string;


  { Make sure that the libmodem component can find the modem files }

  Modem.LibModem.LibModemPath := Modem.ModemCapFolder;

  { Load existing modem configuration }

  INIFile := TINIFile.Create (FileName);


    Modem.SelectedDevice.ModemFile := INIFile.ReadString ('Modem', 'File', '');

    Modem.SelectedDevice.Manufacturer := INIFile.ReadString ('Modem', 'Manufacturer', '');

    Modem.SelectedDevice.Name := INIFile.ReadString ('Modem', 'Name', '');

    { Set a default configuration}

    ModemConfig := Modem.DefaultDeviceConfig;

    { Load the modem configuration }

    ModemConfig.Manufacturer := Modem.SelectedDevice.Manufacturer;

    ModemConfig.ModemName := Modem.SelectedDevice.Name;

    ModemConfig.AttachedTo := INIFile.ReadString ('Settings', 'ComPort', 'unknown');

    ModemConfig.DataBits := INIFile.ReadInteger ('Settings', 'DataBits', 8);

    WorkStr := INIFile.ReadString ('Settings', 'Parity', 'None');

    if WorkStr = 'Even' then

      ModemConfig.Parity := pEven

    else if WorkStr = 'Odd' then

      ModemConfig.Parity := pOdd

    else if WorkStr = 'Mark' then

      ModemConfig.Parity := pMark

    else if WorkStr = 'Space' then

      ModemConfig.Parity := pSpace


      ModemConfig.Parity := pNone;

    ModemConfig.StopBits := INIFile.ReadInteger ('Settings', 'StopBits', 1);

    WorkStr := INIFile.ReadString ('Settings', 'SpeakerVolume', 'Med');

    if WorkStr = 'Low' then

      ModemConfig.SpeakerVolume := svLow

    else if WorkStr = 'High' then

      ModemConfig.SpeakerVolume := svHigh


      ModemConfig.SpeakerVolume := svMed;

    WorkStr := INIFile.ReadString ('Settings', 'SpeakerMode', 'Dial');

    if WorkStr = 'Off' then

      ModemConfig.SpeakerMode := smOff

    else if WorkStr = 'On' then

      ModemConfig.SpeakerMode := smOn


      ModemConfig.SpeakerMode := smDial;

    WorkStr := INIFile.ReadString ('Settings', 'FlowControl', 'Hard');

    if WorkStr = 'Off' then

      ModemConfig.FlowControl := TApdModemFlowControl (fcOff)

    else if WorkStr = 'Soft' then

      ModemConfig.FlowControl := fcSoft


      ModemConfig.FlowControl := fcHard;

    if INIFile.ReadBool('Settings', 'ErrorControlOn', True) then

      ModemConfig.ErrorControl := [ecOn]


      ModemConfig.ErrorControl := [];

    if INIFile.ReadBool('Settings', 'ErrorControlOff', False) then

      ModemConfig.ErrorControl := ModemConfig.ErrorControl + [ecOff];

    if INIFile.ReadBool('Settings', 'ErrorControlForced', False) then

      ModemConfig.ErrorControl := ModemConfig.ErrorControl + [ecForced];

    if INIFile.ReadBool('Settings', 'ErrorControlCellular', False) then

      ModemConfig.ErrorControl := ModemConfig.ErrorControl + [ecCellular];

    ModemConfig.Compression := INIFile.ReadBool ('Settings', 'Compression', True);

    WorkStr := INIFile.ReadString ('Settings', 'Modulation', 'CCITT');

    if WorkStr = 'Bell' then

      ModemConfig.Modulation := smBell

    else if WorkStr = 'CCITT_V23' then

      ModemConfig.Modulation := smCCITT_V23


      ModemConfig.Modulation := smCCITT;

    ModemConfig.ToneDial := INIFile.ReadBool ('Settings', 'ToneDial', True);

    ModemConfig.BlindDial := INIFile.ReadBool ('Settings', 'BlindDial', False);

    ModemConfig.CallSetupFailTimeout := INIFile.ReadInteger ('Settings', 'CallSetupFailTimeout', 60);

    ModemConfig.InactivityTimeout := INIFile.ReadInteger ('Settings', 'InactivityTimeout', 0);

    ModemConfig.ExtraSettings := INIFile.ReadString ('Settings', 'ExtraSettings', '');

    { Store the configuration }

    Modem.SetDevConfig (ModemConfig);




  { Select the modem }

  { The first time through, this will prompt for the modem.  If the

    configuration is then saved, the user will not be prompted. }



For C++ Builder:

void __fastcall LoadModemConfiguration (AnsiString  FileName,

                                        TAdModem   *Modem)


  TIniFile        *INIFile;

  TApdModemConfig  ModemConfig;

  AnsiString       WorkStr;

  // Make sure that the libmodem component can find the modem files }

  Modem->LibModem->LibModemPath = Modem->ModemCapFolder;

  // Load existing modem configuration }

  INIFile = new TIniFile (FileName);

  Modem->SelectedDevice->ModemFile = INIFile->ReadString ("Modem", "File", "");

  Modem->SelectedDevice->Manufacturer = INIFile->ReadString ("Modem", "Manufacturer", "");

  Modem->SelectedDevice->Name = INIFile->ReadString ("Modem", "Name", "");

  // Get a default configuration

  ModemConfig = Modem->DefaultDeviceConfig ();

  // Load the configuration

  ModemConfig.Manufacturer = Modem->SelectedDevice->Manufacturer;

  ModemConfig.ModemName = Modem->SelectedDevice->Name;

  ModemConfig.AttachedTo = INIFile->ReadString ("Settings", "ComPort", "unknown");

  ModemConfig.DataBits = INIFile->ReadInteger ("Settings", "DataBits", 8);

  WorkStr = INIFile->ReadString ("Settings", "Parity", "None");

  if (WorkStr == "Even")

    ModemConfig.Parity = pEven;

  else if (WorkStr == "Odd")

    ModemConfig.Parity = pOdd;

  else if (WorkStr == "Mark")

    ModemConfig.Parity = pMark;

  else if (WorkStr == "Space")

    ModemConfig.Parity = pSpace;


    ModemConfig.Parity = pNone;

  ModemConfig.StopBits = INIFile->ReadInteger ("Settings", "StopBits", 1);

  WorkStr = INIFile->ReadString ("Settings", "SpeakerVolume", "Med");

  if (WorkStr == "Low")

    ModemConfig.SpeakerVolume = svLow;

  else if (WorkStr == "High")

    ModemConfig.SpeakerVolume = svHigh;


    ModemConfig.SpeakerVolume = svMed;

  WorkStr = INIFile->ReadString ("Settings", "SpeakerMode", "Dial");

  if (WorkStr == "Off")

    ModemConfig.SpeakerMode = smOff;

  else if (WorkStr == "On")

    ModemConfig.SpeakerMode = smOn;


    ModemConfig.SpeakerMode = smDial;

  WorkStr = INIFile->ReadString ("Settings", "FlowControl", "Hard");

  if (WorkStr == "Off")

    ModemConfig.FlowControl = Admdm::fcOff;

  else if (WorkStr == "Soft")

    ModemConfig.FlowControl = fcSoft;


    ModemConfig.FlowControl = fcHard;


  if (INIFile->ReadBool("Settings", "ErrorControlOn", True))

    ModemConfig.ErrorControl << ecOn;

  if (INIFile->ReadBool("Settings", "ErrorControlOff", False))

    ModemConfig.ErrorControl << ecOff;

  if (INIFile->ReadBool("Settings", "ErrorControlForced", False))

    ModemConfig.ErrorControl << ecForced;

  if (INIFile->ReadBool("Settings", "ErrorControlCellular", False))

    ModemConfig.ErrorControl << ecCellular;

  ModemConfig.Compression = INIFile->ReadBool ("Settings", "Compression", True);

  WorkStr = INIFile->ReadString ("Settings", "Modulation", "CCITT");

  if (WorkStr == "Bell")

    ModemConfig.Modulation = smBell;

  else if (WorkStr == "CCITT_V23")

    ModemConfig.Modulation = smCCITT_V23;


    ModemConfig.Modulation = smCCITT;

  ModemConfig.ToneDial = INIFile->ReadBool ("Settings", "ToneDial", True);

  ModemConfig.BlindDial = INIFile->ReadBool ("Settings", "BlindDial", False);

  ModemConfig.CallSetupFailTimeout = INIFile->ReadInteger ("Settings", "CallSetupFailTimeout", 60);

  ModemConfig.InactivityTimeout = INIFile->ReadInteger ("Settings", "InactivityTimeout", 0);

  ModemConfig.ExtraSettings = INIFile->ReadString ("Settings", "ExtraSettings", "");

  // Set the device configuration.  If a configuration has not been loaded

  // before, this will prompt the user.

  Modem->SetDevConfig (ModemConfig);

  delete INIFile;


  // Select the modem



LoadModemConfiguration can be called at any time.  The first time that it is called, the user will be prompted for their modem configuration.  Once this configuration has been saved by SaveModemConfiguration, the user will no longer be prompted.

This site is not affiliated, endorsed, or otherwise associated with the entity formerly known as TurboPower Software. The owners and maintainers of were merely meager employees of the aforementioned organization, providing this site out of the pure goodness of their collective hearts. Logo

Last updated: July 22, 2003.