如何在程序中拨号和挂断?(100分)

  • 主题发起人 主题发起人 layman2000
  • 开始时间 开始时间
L

layman2000

Unregistered / Unconfirmed
GUEST, unregistred user!
我是通过电话拨号上网的,需要向远程数据库提交数据,在程序中如何实现拨号和挂断呢?
1.拨通网络
2.提交数据
3.挂断
 
可以调用API,直接拨号就可以了。

如下:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
Error:integer;
begin
Error:=winexec('rundll32.exe rnaui.dll,RnaDial'+'拨号连接因特网',9);
if Error=0 then
Showmessage('系统内存耗尽');
if Error=ERROR_BAD_FORMAT then
Showmessage('拨号程序是非法32位可执行程序');
if Error=ERROR_FILE_NOT_FOUND then
Showmessage('拨号程序么没有找到');
if Error=ERROR_PATH_NOT_FOUND then
Showmessage('拨号程序所在路径不正确');

end;

end.
 
一位富翁以前写的获取当前的拨号连接,且可以挂断连接的控件。
用法:HangUpConn()挂断连接。

unit RAS;
//written by David Jiang in Oct. 24th 1999
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
const
RASCS_DONE = $2000;
RASCS_Connected = RASCS_DONE;
RASCS_Disconnected = RASCS_DONE + 1;
RAS_MaxDeviceType = 16;
{$IFDEF WINVER31}
{Version 3.x sizes }
RAS_MaxEntryName = 20;
RAS_MaxDeviceName = 32;
{$ELSE}
{Version 4.x sizes }
RAS_MaxEntryName = 256;
RAS_MaxDeviceName = 128;
{$ENDIF}
type
THRasConn = Longint;
TRasConnState = Integer;
LPRasConn = ^TRasConn;
TRasConn = record
dwSize: Longint;
hrasconn: THRasConn;
szEntryName: Array[0..RAS_MaxEntryName] of AnsiChar;
{$IFNDEF WINVER31}
szDeviceType: Array[0..RAS_MaxDeviceType] of AnsiChar;
szDeviceName: Array[0..RAS_MaxDeviceName] of AnsiChar;
{$ENDIF}
{$IFDEF WINVER41}
szPhonebook: Array[0..MAX_PATH - 1] of AnsiChar;
dwSubEntry: Longint;
{$ENDIF}
end;
TRasConnStatus = record
dwSize: Longint;
rasconnstate: TRasConnState;
dwError: LongInt;
szDeviceType: Array[0..RAS_MaxDeviceType] of AnsiChar;
szDeviceName: Array[0..RAS_MaxDeviceName] of AnsiChar;
{$IFDEF WINVER41}
swPhoneNumber: Array[0..RAS_MaxPhoneNumber] of AnsiChar;
{$ENDIF}
end;
function RasHangUp(hConn:THRasConn):Longint;stdcall;
external 'rasapi32.dll' name 'RasHangUpA';
function RasEnumConnections( rasconnArray: LPRasConn; var lpcb: Longint;
var lpcConnections: Longint ): Longint; stdcall;
external 'rasapi32.dll' name 'RasEnumConnectionsA';
function RasGetConnectStatus( hConn: THRasConn; var lpStatus: TRasConnStatus
): Longint; stdcall;
external 'rasapi32.dll' name 'RasGetConnectStatusA';
type
TRAS = class(TComponent)
private
{ Private declarations }
rasconn:array [0..15] of TRasConn;
FEnabled: Boolean;
timer:Ttimer;
FOndisconnected,FOnconnected: TNotifyEvent;
procedure Ontimer(sender:Tobject);
procedure SetOnconnected(Value: TNotifyEvent);
procedure SetOndisconnected(Value: TNotifyEvent);
procedure SetEnabled(Value: Boolean);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function HangUpConn(num:integer=0):boolean;
published
{ Published declarations }
property Onconnected: TNotifyEvent read FOnconnected write SetOnconnected;
property Ondisconnected: TNotifyEvent read FOndisconnected write SetOndisconnected;
property Enabled: Boolean read FEnabled write SetEnabled default True;
end;
procedure Register;
implementation

function TRAS.HangUpConn(num:integer=0):boolean;
begin
result:=RasHangUp(rasconn[num].hrasconn)=0;
end;
procedure TRAS.SetOndisconnected(value:TNotifyEvent);
begin
if assigned(FOndisconnected) then FOndisconnected(self);
FOndisconnected:=value;
end;
procedure Tras.SetOnconnected(value:TNotifyEvent);
begin
if assigned(FOnconnected) then FOnconnected(self);
FOnconnected:=value;
end;
procedure TRAS.SetEnabled(value:Boolean);
begin
if Value <> FEnabled then
begin
FEnabled := Value;
if timer<>nil then
timer.Enabled :=value;
end;
end;
procedure TRAS.Ontimer(sender:Tobject);
var
return:dword;
size,num:integer;
i:integer;
connstatus:TRasConnStatus;
begin
size:=16*sizeof(TRasConn);
rasconn[0].dwsize:=sizeof(Trasconn);
num:=0;

return:=RasEnumConnections(@rasconn,size,num);
if return<>0 then exit;
for i:=0 to num-1 do
begin
connstatus.dwSize:=sizeof(Trasconnstatus);
if RasGetConnectStatus(rasconn.hrasconn,
connstatus)=0 then
case connstatus.rasconnstate of
RASCS_Connected:if assigned(FOnconnected)
then FOnconnected(sender);
RASCS_DisConnected:if assigned(FOndisconnected)
then FOndisconnected(sender);
end;
end;
end;

constructor TRAS.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEnabled := True;
timer:=Ttimer.Create(self);
timer.OnTimer :=ontimer;

end;

destructor TRAS.Destroy;
begin
inherited Destroy;
end;
procedure Register;
begin
RegisterComponents('Samples', [TRAS]);
end;
end.
 
http://go8.163.com/delphibbs/
上有一个例子
参考参考
 
我用turbopower async professional实现了,谢谢各位的热情帮助。
 
是什么方法~~
 
RasDial and RasHangUp
 
lichengbin能说得清楚些吗?
 
后退
顶部