home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / delphi / DIALER / DIALER.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-12  |  2.8 KB  |  104 lines

  1. { TDialer component for Borland DELPHI, Version 1.00.
  2.      Freeware.
  3.   Original code by Artchil Gogava, ArGo Software Design, Toronto, Canada.
  4. October 1995.
  5.      Internet: 75231.330@compuserve.com
  6.      www     : http://www.icacomp.com/customers/agogava
  7.   Changes for Borland DELPHI 2.0 made by:
  8.      Ruud Overdijk, Kwarts produkties, Hilversum, The Netherlands, April 1996.
  9.      Internet : roverdyk@worldaccess.nl
  10.      Compuserve :  71613,1733 }
  11.  
  12. unit Dialer;
  13.  
  14. interface
  15.  
  16. uses
  17.   Windows, SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
  18.   Controls, Forms, Dialogs;
  19. type
  20.  
  21.   TComPort = (dpCOM1,dpCOM2,dpCOM3,dpCOM4);
  22.   TMethod  = (dmTone,dmPulse);
  23.  
  24.   TDialer = class(TComponent)
  25.   private
  26.     { Private declarations }
  27.     FComPort : TComPort;
  28.     FNumberToDial : string;
  29.     FConfirm : boolean;
  30.     FMethod : TMethod;
  31.   protected
  32.     { Protected declarations }
  33.   public
  34.     { Public declarations }
  35.  
  36.     procedure Execute;
  37.   published
  38.     property ComPort : TComPort read FComPort
  39.                  write FComPort;
  40.     property Confirm : boolean read FConfirm
  41.                  write FConfirm;
  42.     property Method  : TMethod read FMethod
  43.                  write FMethod;
  44.     property NumberToDial : string read FNumberToDial
  45.                  write FNumberToDial;
  46.     { Published declarations }
  47.   end;
  48.  
  49. procedure Register;
  50.  
  51. implementation
  52.  
  53. procedure Register;
  54. begin
  55.   RegisterComponents('Samples', [TDialer]);
  56. end;
  57.  
  58. procedure TDialer.Execute;
  59. var
  60.   s        : string;
  61.   hCommFile     : THandle;
  62.   Status     : LongBool;
  63.   NumberWritten    : DWORD;
  64. begin
  65.   if FConfirm then
  66.   begin
  67.   if MessageDlg('About to dial the number '+FNumberToDial+'. Are you sure?',
  68.       mtConfirmation, [mbYes,mbNo], 0)=mrNo then Exit;
  69.   end;
  70.   {Open Com Port}
  71.   s:='COM'+Chr(49+Ord(FComPort));
  72.   hCommFile:= CreateFile( PChar(s), GENERIC_WRITE,
  73.                                 0, {not shared}
  74.                                 nil, {no security ??}
  75.                                 OPEN_EXISTING,
  76.                                 FILE_ATTRIBUTE_NORMAL,
  77.                                 0 {template} );
  78.   if hCommFile=INVALID_HANDLE_VALUE then
  79.   begin
  80.     MessageDlg('Unable to open '+s,mtError,[mbOk], 0);
  81.     Exit;
  82.   end;
  83.   {Create a string to send to modem}
  84.   s:='ATDT'+FNumberToDial+#13+#10;
  85.   if FMethod=dmPulse then s[4]:='P';
  86.   {Send phone number to modem}
  87.   NumberWritten:=0;
  88.   Status:=WriteFile( hCommFile,PChar(s)[0],
  89.                      Length(s),
  90.                      NumberWritten,
  91.                      nil);
  92.   if Status then
  93.   begin
  94.     MessageDlg('Pick up phone',mtInformation,[mbOk], 0);
  95.     WriteFile(hCommFile,'ATH'^M^J,5,NumberWritten,nil);
  96.   end
  97.   else
  98.     MessageDlg('Unable to dial number',mtError,[mbOk], 0);
  99.   {Close communication port}
  100.   CloseHandle(hCommFile);
  101. end;
  102.  
  103. end.
  104.