Delphi的拨号连接类
2008-04-09 04:31:50来源:互联网 阅读 ()
前一阵因为工作需要写了一个类来进行windows拨号,整理了一下,多封装了几个windows ras api,放上来大家提提意见。现在支持读取windows拨号连接列表、拨号、挂断、创建/删除连接,可以适用98/2000/XP,windows me 和NT没测试过,想来应该是可以的。以后有时间写成component,加入对拨号事件的支持。
uses
ras, Classes, SysUtils, StrUtils, Windows, Forms;
type
ERasError = Exception;
type
TRASConnection = class
private
FPlatForm: integer;
FConnected: Boolean;
FRasEntries: TStringList;
FRasConn: HRASCONN;
FParams: RasDialParams;
Ferrno: integer;
function GetPassword: string;
procedure SetPassword(Password: string);
function GetPhoneNo: string;
procedure SetPhoneNo(Number: string);
function GetCallBack: string;
procedure SetCallBack(Number: string);
function GetDomain: string;
procedure SetDomain(Domain: string);
function GetUserName: string;
procedure SetUserName(UserName: string);
function GetEntryName: string;
procedure SetEntryName(Entry: string);
function GetConnected: Boolean;
procedure SetConnected(AValue: Boolean);
function GetRasEntries: TStringList;
public
property RasEntries: TStringList read GetRasEntries;
property PhoneNumber: string read GetPhoneNo write SetPhoneNo;
property CallBackNumber: string read GetCallBack write SetCallBack;
property Domain: string read GetDomain write SetDomain;
property EntryName: string read GetEntryName write SetEntryName;
property username: string read GetUsername write SetUsername;
property password: string read GetPassword write SetPassword;
property Active: Boolean read GetConnected write SetConnected;
procedure Connect;
procedure DisConnect;
function GetErrorCode: integer;
procedure FreeAndHangup;
constructor Create; reintroduce;
destructor Destroy; override;
procedure CreateRasEntry;
procedure DeleteRasEntry(AEntryName: string);
//function GetErrorReason: integer;
end;
implementation
{ TRASConnection }
procedure TRASConnection.Connect;
var
i: integer;
s: string;
begin
FParams.dwSize := sizeof(RasDialParams);
i := RasDial(nil, nil, @FParams, 0, nil, @FRasConn);
if i <> 0 then begin
Ferrno := i;
case i of
691: s := ''''身分验证失败!'''';
692: s := ''''打开端口失败!'''';
676: s := ''''线路忙,请稍候再拨!'''';
677: s := ''''语音响应错误!'''';
678: s := ''''没有应答!'''';
679: s := ''''无载波信号!'''';
680: s := ''''无拨号音!'''';
else
s := ''''未知错误!'''';
end;
RasHangUp(FRasConn);
raise ERasError.Create(s);
end
else FConnected := True;
end;
procedure TRASConnection.DisConnect;
begin
RasHangup(FRasConn);
FRasConn := 0;
end;
function TRASConnection.GetCallBack: string;
begin
Result := string(FParams.szCallbackNumber);
end;
function TRASConnection.GetConnected: Boolean;
var
i, len, num: integer;
x: array of RASCONN;
begin
Result := False;
SetLength(x, 1);
x[0].dwSize := sizeof(RASCONN);
len := x[0].dwSize;
num := 0;
RasEnumConnections(@x[0], @len, @num);
if num > 0 then begin
SetLength(x, num);
x[0].dwSize := sizeof(RASCONN);
len := x[0].dwSize; num := 0;
RasEnumConnections(@x[0], @len, @num);
for i := 1 to num do
if StrComp(x[i - 1].szEntryName, PChar(EntryName)) = 0 then begin
FRasConn := x[i - 1].hrasconn;
Result := True;
Break;
end;
end;
SetLength(x, 0);
end;
function TRASConnection.GetDomain: string;
begin
Result := string(FParams.szDomain);
end;
function TRASConnection.GetErrorCode: integer;
begin
Result := FErrno;
end;
function TRASConnection.GetPassword: string;
begin
Result := ''''**********'''';
end;
function TRASConnection.GetPhoneNo: string;
begin
Result := string(FParams.szPhoneNumber);
end;
function TRASConnection.GetEntryName: string;
begin
Result := string(FParams.szEntryName);
end;
function TRASConnection.GetUserName: string;
begin
Result := string(FParams.szUserName);
end;
procedure TRASConnection.SetCallBack(Number: string);
begin
StrLCopy(FParams.szCallbackNumber, PChar(Number), sizeof(FParams.szCallbackNumber) - 1);
end;
procedure TRASConnection.SetConnected(AValue: Boolean);
begin
if AValue and not GetConnected then Connect
else if not AValue and GetConnected then DisConnect;
end;
procedure TRASConnection.SetDomain(Domain: string);
begin
StrLCopy(FParams.szDomain, PChar(Domain), sizeof(FParams.szDomain) - 1);
end;
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:所见及所得的类分析跟踪器
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash