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

📄 exdials0.~pas

📁 一卡通离线积分系统
💻 ~PAS
字号:
unit exdials0;
{
TMagRas Dialling Simple Example
===============================

Dial, monitor and hang-up a RAS connection using information 
already specified in the phonebook entry. 

Created by Angus Robertson, Magenta Systems Ltd, England
in 2000, delphi@magsys.co.uk, http://www.magsys.co.uk/delphi/
Last updated: 30th April 2001

To load this example, the TMagRas components need to have been previously
installed on the component palette.

}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, magrascon, magrasapi, KsControls, KsButtons,
  KsSkinButtons, KsHooks, KsForms, KsSkinForms, KsPanels, KsSkinPanels;

type
  TConnectFrom = class(TForm)
    MyPl: TSeSkinPanel;
    ConnList: TListBox;
    doDial: TSeSkinButton;
    SeSkinForm1: TSeSkinForm;
    TimerStatus: TTimer;
    MagRasCon: TMagRasCon;
    doHangup: TSeSkinButton;
    doExit: TSeSkinButton;
    procedure doExitClick(Sender: TObject);
    procedure TimerStatusTimer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure doHangupClick(Sender: TObject);
    procedure doDialClick(Sender: TObject);
    procedure MagRasConStateChanged(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ConnectFrom: TConnectFrom;
  ConnHandle: HRasConn ;         	// handle for current connection
  ConnName: string ;                // name of current connection
  LastState: integer ;				// used to check if state has changed
  DialHandle: HRasConn ;         	// handle for dialled connection
  DialName: string ;                // name of dialled connection

implementation

{$R *.DFM}
uses uMain;
procedure TConnectFrom.doExitClick(Sender: TObject);
begin
     ConnectFrom.Close;
end;

// main event handler, while this is being processed RAS will wait
// called in response to CurrentStatusEx in the timer event, or
// while dialling a call (events much faster)

procedure TConnectFrom.MagRasConStateChanged(Sender: TObject);
var
	info: string ;
begin

// check type of event
	info := '' ;
    case MagRasCon.StateEventSource of
    	SourceDial: info := '拨号: ' ;
    	SourceStatus: info := '状态: ' ;
    	SourceHangup: info := '挂断: ' ;
	end ;

// see if new event, else display it
	if LastState = MagRasCon.ConnectState then exit ;
    LastState := MagRasCon.ConnectState ;
// ConnLog.Lines.Add (info + MagRasCon.StatusStr +	' (' + IntToStr (LastState) + ')') ;

// something has changed, talk to user
// ConnectState can be checked against literals in MagRasApi
//    to determine current state of connection
//	LabelStat.Caption := MagRasCon.StatusStr ;
    if (MagRasCon.ConnectState < RASCS_Connected) then
//    									LabelOnline.Caption := '正在拨号' ;
	if (MagRasCon.ConnectState = RASCS_Connected) then
//    									LabelOnline.Caption := '在线' ;
  Close;
	if (MagRasCon.ConnectState = RASCS_DisConnected) then
//    									LabelOnline.Caption := '挂断' ;

// if dialling need to see what's happened
	if DialHandle <> 0 then
    begin

	// online OK, restart timer
		if (MagRasCon.ConnectState = RASCS_Connected) then
        begin
            ConnHandle := DialHandle ;
			DialHandle := 0 ;
    	    TimerStatus.Enabled := true ;
		end ;

	// dialling failed, either an error or disconnected
		if ((MagRasCon.ConnectState > RASBase) and
	            (MagRasCon.ConnectState < RASCS_Paused)) or
	             (MagRasCon.ConnectState = RASCS_Disconnected) then
		begin
	// disconnect, returns when done or after three seconds, no StateChanged
            ConnHandle := DialHandle ;
			DialHandle := 0 ;
			MagRasCon.DisconnectEx (ConnHandle, 0, 3000, false) ;
	        TimerStatus.Enabled := true ;
            // reset is done in timer event
		end ;
	end ;
end;

// to monitor a RAS connection, you only need a timer event to check
// if there's an active RAS connection and then check it's state
// this timer is set for once per second, and may miss some state
// messages during dialling and authentication that happen very fast
// the timer internval could be shorter, but on Win9x this may overload RAS

procedure TConnectFrom.TimerStatusTimer(Sender: TObject);
begin

// check for active connections
// Win9x lists connection when it starts dialling
// WinNT/2K only list connection if it answers
	MagRasCon.GetConnections ;

// details of active connections are now available in Connections list
// no active connections, see if already closed down
	if MagRasCon.Connections.Count = 0 then
	begin
		if ConnHandle = 0 then exit ;
        ConnHandle := 0 ;
        DialName := '' ;
        doHangup.Enabled := false ;
        doDial.Enabled := true ;
//        LabelStat.Caption := '' ;
//        LabelOnline.Caption := '离线' ;
//        ConnLog.Lines.Add ('连接离线状态') ;
        exit ;
    end ;

// connection list has changed, that means a new call
	if MagRasCon.ConnChangedFlag then
    begin
      // assume only a single connection (there may be more)
	    ConnHandle := MagRasCon.Connections.RasConn (0) ;
    	ConnName := MagRasCon.Connections.EntryName (0) ;
//	    LabelConn.Caption := ConnName ;
        doHangup.Enabled := true ;
        if DialName <> ConnName then
//	        ConnLog.Lines.Add ('找到新的连接: ' + ConnName) ;
	end ;

// get state of current connection
// calls StateChanged event where all checking is done
    MagRasCon.CurrentStatusEx (ConnHandle, 0) ;
end;

procedure TConnectFrom.FormCreate(Sender: TObject);
begin
	LastState := 0 ;
//	LabelConn.Caption := '' ;
//    LabelStat.Caption := '' ;
 //   ConnLog.Lines.Clear ;
// see if RAS has been installed
	if MagRasCon.TestRAS then
    begin
    // get list of phonebook entries
		MagRasCon.GetPhoneBookEntries ;
    //  MagRasCon.PhoneBookEntries.Sort ;  4.60 already sorted
		ConnList.Items.Assign (MagRasCon.PhoneBookEntries) ;	 // display it
	    TimerStatusTimer (self) ;  // avoid waiting one second until timer expires
        TimerStatus.Enabled := true ;
	end
    else
    begin
	 	uMain.MainForm.ShowMessage('没有安装拨号组件') ;
    end ;
end;

procedure TConnectFrom.doHangupClick(Sender: TObject);
begin
  if (DialHandle = 0) and (ConnHandle = 0) then exit ;
	doHangup.Enabled := false ;
  doDial.Enabled := true ;

// disconnect, returns when done or after three seconds, calls StateChanged
	if ConnHandle = 0 then ConnHandle := DialHandle ;
	MagRasCon.DisconnectEx (ConnHandle, 0, 3000, true) ;
  MyPl.Rolled := False;
end;

procedure TConnectFrom.doDialClick(Sender: TObject);
begin
	if ConnList.ItemIndex < 0 then exit ;

// entry to dial
    DialName := ConnList.Items [ConnList.ItemIndex] ;
//    LabelConn.Caption := DialName ;

// stop timer since dialling creates events
    TimerStatus.Enabled := false ;
    doDial.Enabled := false ;

// set phonebook entry to dial
	MagRasCon.EntryName := DialName ;
	MagRasCon.PhoneNumber :=	'' ;  // use the one in the phonebook
//  	ConnLog.Lines.Add ('正在尝试拨号连接: ' + DialName) ;

// start connection (sets handle)
	DialHandle := 0 ;
  	if MagRasCon.AutoConnectEx (DialHandle) <> 0 then
	begin
        // fails here is dialling did not even start
		uMain.MainForm.ShowMessage('拨号失败 - ' + MagRasCon.StatusStr) ;
		beep ;
    TimerStatus.Enabled := true ;
	  doDial.Enabled := true ;
    exit;
	end ;

// dialling started OK
// dial connection or failure is checked in StateChanged event handler
	doHangup.Enabled := true ;
  MyPl.Rolled := true;
end;


end.

⌨️ 快捷键说明

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