⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 delphi下的号码翻译控件
💻 PAS
字号:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, OleCtrls, AMITAPIPROLib_TLB;

type
  TFormMain = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Readme1: TMenuItem;
    Exit1: TMenuItem;
    PleaseClickMe1: TMenuItem;
    FrameCallingFrom: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    ComboLocations: TComboBox;
    ComboCountries: TComboBox;
    TextAreaCode: TEdit;
    TextNumber: TEdit;
    Label1: TLabel;
    LabelDisplayableNumber: TLabel;
    CommandShowLocations: TButton;
    CommandCall: TButton;
    LabelAreaCode: TLabel;
    Label4: TLabel;
    CheckTranslateNumbers: TCheckBox;
    amTapiPro1: TamTapiPro;
    Label5: TLabel;
    LabelDialableNumber: TLabel;
    procedure Readme1Click(Sender: TObject);
    procedure PleaseClickMe1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure ComboLocationsChange(Sender: TObject);
    procedure CommandShowLocationsClick(Sender: TObject);
    procedure CommandCallClick(Sender: TObject);
    procedure CheckTranslateNumbersClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure FillLocations();
procedure SetDefaultNumber();

var
  FormMain: TFormMain;

implementation

uses ReadMe;

{$R *.dfm}

procedure TFormMain.Readme1Click(Sender: TObject);
begin
 formReadMe.Show;
end;

procedure TFormMain.PleaseClickMe1Click(Sender: TObject);
begin
 FormReadMe.Show;
end;

procedure TFormMain.Exit1Click(Sender: TObject);
begin
 Self.Close;
end;

procedure TFormMain.ComboLocationsChange(Sender: TObject);
begin
    //Set the newley selected CurrenLocationID
    amTapiPro1.CurrentLocationID := ComboLocations.ItemIndex;
end;

procedure TFormMain.CommandShowLocationsClick(Sender: TObject);
var NumberToCall, Country : String;
begin
  //Parse out the CountryID from the Country Name
  if not(ComboCountries.Text = '') then
   begin
      Country := ComboCountries.Text;
      Country := Copy(Country, 1 + Pos('(',Country),Length(Country));
      Country := Copy(Country, 0, Length(Country)- 1);
   end;

  //Construct a canonical number
  NumberToCall := '+' + Country + ' (' + TextAreaCode.Text + ') ' + TextNumber.Text;
  //Show the Location Dialing Rules Dialog
  //Pass in the number to be called so that the user can see the efect
  //of changing the dialing rules on the number displayed at the bottom of
  //the dialog
  amTapiPro1.ShowLocationDialog(self.handle, NumberToCall);
  //Re-fill the Locations combo, the user may have added or deleted locations
  FillLocations;
end;

procedure TFormMain.CommandCallClick(Sender: TObject);
var
 NumberToCall: WideString;
 DisplayableNumber: String;
 Country : String;
begin
  if (CheckTranslateNumbers.Checked = True) then //If the user wants the number translated
   begin
      if ComboCountries.Text = '' then
       begin
          ShowMessage (' set a Location');
          Exit;
       end;
      Country := ComboCountries.Text;
      //Parse out the CountryID from the Country Name
      Country := Copy(Country, 1 + Pos('(',Country),Length(Country));
      Country := Copy(Country, 0, Length(Country)- 1);
      //Construct a canonical number
      NumberToCall := '+' + Country + ' (' + TextAreaCode.Text + ') ' + TextNumber.Text;
      //Translate number
      if not (TextNumber.Text = '') then
       DisplayableNumber := amTapiPro1.TranslateNumber(NumberToCall)
      else
       //TAPI calls telephone numbers addresses
       ShowMessage ('Invalid Telephone Number');
   end
  else
   begin
      //Number without any translation selected
      NumberToCall := TextNumber.Text;
      DisplayableNumber := NumberToCall;
    end;

  LabelDisplayableNumber.Caption := DisplayableNumber;
  LabelDialableNumber.Caption := NumberToCall;

  //NumberToCall can now be passed to amTapi Pro MakeCall for dialing
  //Not included in this example
end;

procedure TFormMain.CheckTranslateNumbersClick(Sender: TObject);
begin
 if (CheckTranslateNumbers.Checked = False) then //unchecked;
  begin
   ComboLocations.Enabled := False;
   ComboCountries.Enabled := False;
   ComboLocations.Text := '';
   ComboCountries.Text := '';
   ComboLocations.Color :=clBtnFace;
   ComboCountries.Color := clBtnFace;
   TextAreaCode.Color := clBtnFace;
   TextAreaCode.Text := '';
   LabelAreaCode.Enabled := False;
   CommandShowLocations.Enabled := False;
   TextAreaCode.Enabled := False;
   FrameCallingFrom.Enabled := False;
  end
 else
  begin
   ComboLocations.Enabled := True;
   ComboCountries.Enabled := True;
   ComboLocations.Text := '';
   ComboCountries.Text := '';
   ComboLocations.Color := clWindow;
   ComboCountries.Color := clWindow;
   TextAreaCode.Color := clWindow;
   TextAreaCode.Text := '';
   LabelAreaCode.Enabled := True;
   CommandShowLocations.Enabled := True;
   TextAreaCode.Enabled := True;
   FrameCallingFrom.Enabled := True;
   ComboLocations.ItemIndex := amTapiPro1.CurrentLocationID;
   ComboCountries.Text := amTapiPro1.CurrentCountryName;
   TextAreaCode.Text := amTapiPro1.CurrentAreaCode;
  end; ;

end;

procedure TFormMain.FormCreate(Sender: TObject);
var x: integer;
begin
  //Load the Countries combo with all known country names
  for x := 0 to amTapiPro1.NumberOfCountries - 1 do
      ComboCountries.Items.Add(amTapiPro1.GetCountryName(x));
  //Load the Locations combo with all known locations, set to display the current location
  FillLocations;
  //To aid the user
  //Pre-load the number to be called area code to the current area code and
  //pre-load the number to be called Country name
  SetDefaultNumber;
end;

procedure FillLocations();
var x: integer;
begin
  FormMain.ComboLocations.Clear;
  //Load the Locations combo with all known locations
  for x := 0 to (FormMain.amTapiPro1.NumberOfLocations - 1) do
      FormMain.ComboLocations.Items.Add(FormMain.amTapiPro1.GetLocationName(x));
  //Set to display the current location
  FormMain.ComboLocations.ItemIndex := FormMain.amTapiPro1.CurrentLocationID;
end;

procedure SetDefaultNumber();
begin
  //To aid the user (Optional)
  //Pre-load the number to be called area code to the current area code and
  //pre-load the number to be called Country name
  FormMain.ComboCountries.Text := FormMain.amTapiPro1.CurrentCountryName;
  FormMain.TextAreaCode.Text := FormMain.amTapiPro1.CurrentAreaCode;
end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -