📄 dialer.pas
字号:
unit Dialer;
interface
uses
Windows, SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
Controls, Forms, Dialogs, IniFiles;
type
TComPort = (dpCOM1,dpCOM2,dpCOM3,dpCOM4);
TDialer = class(TComponent)
private
{ Private declarations }
FComPort : TComPort;
FNumberToDial : string;
FNameToDial : string;
protected
{ Protected declarations }
public
{ Public declarations }
procedure Execute;
published
property ComPort : TComPort read FComPort write FComPort;
property NumberToDial : string read FNumberToDial write FNumberToDial;
property NameToDial : string read FNameToDial write FNameToDial;
{ Published declarations }
end;
implementation
uses DialerForm;
procedure TDialer.Execute;
var
s : string;
hCommFile : THandle;
Status : LongBool;
NumberWritten : DWORD;
BS1ini: TIniFile;
strPort: string;
begin
BS1Ini := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'BS1.ini'); //Get port (override previous property).
strPort := BS1Ini.ReadString('General', 'DialerPort', '');
BS1Ini.Free;
if strPort = 'com1' then FComPort:=dpCom1
else if strPort = 'com2' then FComPort:=dpCom2
else if strPort = 'com3' then FComPort:=dpCom3
else if strPort = 'com4' then FComPort:=dpCom4;
//frmDialer.label1.caption := 'Phone ' + '''' + FNameToDial + '''' + #13 + 'at ' + FNumberToDial;
if frmDialer.ShowModal = mrOk then begin
if MessageDlg('Phone ' + '''' + FNameToDial + '''' + #13 + 'at ' + FNumberToDial, mtConfirmation, mbOKCancel, 0)<>mrOK then Exit;
if FNumberToDial = '' then exit;
s:='COM'+Chr(49+Ord(FComPort)); //Open Com Port.
hCommFile:= CreateFile( PChar(s), GENERIC_WRITE,
0, {not shared}
nil, {no security ??}
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0 {template} );
if hCommFile=INVALID_HANDLE_VALUE then begin
MessageDlg('Unable to open '+s,mtError,[mbOk], 0);
Exit;
end;
s:='ATDT'+FNumberToDial+#13+#10; //Create a string to send to modem.
NumberWritten:=0; //Send phone number to modem.
Status:=WriteFile( hCommFile,PChar(s)[0],
Length(s),
NumberWritten,
nil);
if Status then begin
MessageDlg('Pick up the phone.' + #13 + 'Click OK after dialing has completed.',mtInformation,[mbOk], 0);
WriteFile(hCommFile,'ATH'^M^J,5,NumberWritten,nil);
end else MessageDlg('Unable to dial number.',mtError,[mbOk], 0);
CloseHandle(hCommFile); //Close communication port.
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -