📄 jvras32.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvRas32.PAS, released on 2001-02-28.
The Initial Developer of the Original Code is S閎astien Buysse [sbuysse att buypin dott com]
Portions created by S閎astien Buysse are Copyright (C) 2001 S閎astien Buysse.
All Rights Reserved.
Contributor(s): Michael Beck [mbeck att bigfoot dott com].
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvRas32.pas,v 1.24 2005/02/17 10:20:46 marquardt Exp $
unit JvRas32;
{$I jvcl.inc}
{$I windowsonly.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
SysUtils, Classes, Controls, Forms,
{$IFDEF VisualCLX}
Qt, QRas32,
{$ENDIF VisualCLX}
{$IFDEF VCL}
Ras32,
{$ENDIF VCL}
Windows, Messages,
// Messages must be after QControls
JvComponent, JvTypes;
type
TJvRas32 = class(TJvComponent)
private
FPhoneBookPath: TFileName;
FPassword: string;
FDeviceName: string;
FUsername: string;
FEntry: string;
FDeviceType: string;
FPhoneNumber: string;
FCallBackNumber: string;
FDomain: string;
FConnection: DWORD;
FHandle: THandle;
FPHandle: THandle;
RASEvent: Word;
FEntryIndex: Integer;
FDummyConnected: Boolean;
FPhoneBook: TStringList;
FOnAuthProject: TNotifyEvent;
FOnAuthChangePassword: TNotifyEvent;
FOnAuthLinkSpeed: TNotifyEvent;
FOnDisconnected: TNotifyEvent;
FOnAuthNotify: TNotifyEvent;
FOnDeviceConnected: TNotifyEvent;
FOnReAuthenticate: TNotifyEvent;
FOnAuthAck: TNotifyEvent;
FOnConnectDevice: TNotifyEvent;
FOnAuthRetry: TNotifyEvent;
FOnAuthenticate: TNotifyEvent;
FOnWaitForModemReset: TNotifyEvent;
FOnOpenPort: TNotifyEvent;
FOnAuthCallback: TNotifyEvent;
FOnRetryAuthentication: TNotifyEvent;
FOnPortOpened: TNotifyEvent;
FOnWaitForCallBack: TNotifyEvent;
FOnPrepareForCallback: TNotifyEvent;
FOnPasswordExpired: TNotifyEvent;
FOnInteractive: TNotifyEvent;
FOnConnected: TNotifyEvent;
FOnAuthenticated: TNotifyEvent;
FOnAllDevicesConnected: TNotifyEvent;
FDll: THandle;
FRasDial: TRasDial;
FRasEnumConnections: TRasEnumConnections;
FRasEnumEntries: TRasEnumEntries;
FRasGetConnectStatus: TRasGetConnectStatus;
FRasGetErrorstring: TRasGetErrorstring;
FRasHangUp: TRasHangUp;
FRasGetEntryDialParams: TRasGetEntryDialParams;
FRasValidateEntryName: TRasValidateEntryName;
FRasCreatePhonebookEntry: TRasCreatePhonebookEntry;
FRasEditPhonebookEntry: TRasEditPhonebookEntry;
FKeepConnected: Boolean;
FAvailable: Boolean;
// function GetPhoneBook: TStringList;
procedure WndProc(var Msg: TMessage);
procedure SetEntryIndex(const Value: Integer);
function GetConnected: Boolean;
function GetPhoneBook: TStrings;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure RefreshPhoneBook;
function Dial(Index: Integer): Boolean;
function HangUp: Boolean;
function CreateNewConnection: Boolean;
function EditConnection(Index: Integer): Boolean;
function GetActiveConnection: string;
property CallBackNumber: string read FCallBackNumber write FCallBackNumber;
property DeviceType: string read FDeviceType;
property DeviceName: string read FDeviceName;
property PhoneNumber: string read FPhoneNumber write FPhoneNumber;
property Domain: string read FDomain write FDomain;
property PhoneBook: TStrings read GetPhoneBook;
property RasAvailable: Boolean read FAvailable;
published
property KeepConnected: Boolean read FKeepConnected write FKeepConnected default False;
// property PhoneBook: TStringList read GetPhoneBook;
property EntryIndex: Integer read FEntryIndex write SetEntryIndex default -1;
property PhoneBookPath: TFileName read FPhoneBookPath write FPhoneBookPath;
property Entry: string read FEntry write FEntry;
property Username: string read FUsername write FUsername;
property Password: string read FPassword write FPassword;
property Connected: Boolean read GetConnected write FDummyConnected stored False;
property OnOpenPort: TNotifyEvent read FOnOpenPort write FOnOpenPort;
property OnPortOpened: TNotifyEvent read FOnPortOpened write FOnPortOpened;
property OnConnectDevice: TNotifyEvent read FOnConnectDevice write FOnConnectDevice;
property OnDeviceConnected: TNotifyEvent read FOnDeviceConnected write FOnDeviceConnected;
property OnAllDevicesConnected: TNotifyEvent read FOnAllDevicesConnected write FOnAllDevicesConnected;
property OnAuthenticate: TNotifyEvent read FOnAuthenticate write FOnAuthenticate;
property OnAuthNotify: TNotifyEvent read FOnAuthNotify write FOnAuthNotify;
property OnAuthRetry: TNotifyEvent read FOnAuthRetry write FOnAuthRetry;
property OnAuthCallback: TNotifyEvent read FOnAuthCallback write FOnAuthCallback;
property OnAuthChangePassword: TNotifyEvent read FOnAuthChangePassword write FOnAuthChangePassword;
property OnAuthProject: TNotifyEvent read FOnAuthProject write FOnAuthProject;
property OnAuthLinkSpeed: TNotifyEvent read FOnAuthLinkSpeed write FOnAuthLinkSpeed;
property OnAuthAck: TNotifyEvent read FOnAuthAck write FOnAuthAck;
property OnReAuthenticate: TNotifyEvent read FOnReAuthenticate write FOnReAuthenticate;
property OnAuthenticated: TNotifyEvent read FOnAuthenticated write FOnAuthenticated;
property OnPrepareForCallback: TNotifyEvent read FOnPrepareForCallback write FOnPrepareForCallback;
property OnWaitForModemReset: TNotifyEvent read FOnWaitForModemReset write FOnWaitForModemReset;
property OnInteractive: TNotifyEvent read FOnInteractive write FOnInteractive;
property OnRetryAuthentication: TNotifyEvent read FOnRetryAuthentication write FOnRetryAuthentication;
property OnPasswordExpired: TNotifyEvent read FOnPasswordExpired write FOnPasswordExpired;
property OnConnected: TNotifyEvent read FOnConnected write FOnConnected;
property OnDisconnected: TNotifyEvent read FOnDisconnected write FOnDisconnected;
property OnWaitForCallBack: TNotifyEvent read FOnWaitForCallBack write FOnWaitForCallBack;
end;
// (rom) renamed
EJvRasError = class(EJVCLException);
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvRas32.pas,v $';
Revision: '$Revision: 1.24 $';
Date: '$Date: 2005/02/17 10:20:46 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
JvJVCLUtils, JvResources;
constructor TJvRas32.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FKeepConnected := False;
FPhoneBookPath := '';
FPassword := '';
FDeviceName := '';
FUsername := '';
FEntry := '';
FDeviceType := '';
FPhoneNumber := '';
FCallBackNumber := '';
FDomain := '';
FConnection := 0;
if AOwner is TWinControl then
{$IFDEF VCL}
FPHandle := (AOwner as TWinControl).Handle
{$ENDIF VCL}
{$IFDEF VisualCLX}
FPHandle := QWidget_winid((AOwner as TWinControl).Handle)
{$ENDIF VisualCLX}
else
// (rom) is this safe?
FPHandle := GetForegroundWindow;
FEntryIndex := -1;
FDll := LoadLibrary(PChar(RsRasDllName));
if FDll <> 0 then
begin
FRasDial := GetProcAddress(FDll, 'RasDialA');
FRasEnumConnections := GetProcAddress(FDll, 'RasEnumConnectionsA');
FRasEnumEntries := GetProcAddress(FDll, 'RasEnumEntriesA');
FRasGetConnectStatus := GetProcAddress(FDll, 'RasGetConnectStatusA');
FRasGetErrorstring := GetProcAddress(FDll, 'RasGetErrorstringA');
FRasHangUp := GetProcAddress(FDll, 'RasHangUpA');
FRasGetEntryDialParams := GetProcAddress(FDll, 'RasGetEntryDialParamsA');
FRasValidateEntryName := GetProcAddress(FDll, 'RasValidateEntryNameA');
FRasCreatePhonebookEntry := GetProcAddress(FDll, 'RasCreatePhonebookEntryA');
FRasEditPhonebookEntry := GetProcAddress(FDll, 'RasEditPhonebookEntryA');
FHandle := AllocateHWndEx(WndProc);
RASEvent := RegisterWindowMessage(RASDialEvent);
if RASEvent = 0 then
RASEvent := WM_RASDialEvent;
end;
FAvailable := (FDll <> 0) and Assigned(FRasDial);
end;
destructor TJvRas32.Destroy;
begin
FPhoneBook.Free;
if RasAvailable then
begin
try
if not KeepConnected then
HangUp;
except
end;
FreeLibrary(FDll);
DeallocateHWndEx(FHandle);
end;
FDll := 0;
inherited Destroy;
end;
function TJvRas32.GetActiveConnection: string;
var
Ret: Longint;
nCB: DWORD;
RasConn: array [0..63] of TRASCONN;
nRasConnCount: DWORD;
I: Integer;
begin
Result := '';
if RasAvailable then
begin
RasConn[0].dwSize := SizeOf(TRASCONN);
nCB := SizeOf(RasConn);
Ret := FRasEnumConnections(@RasConn, nCB, nRasConnCount);
if (Ret <> Success) or (nRasConnCount = 0) then
Exit;
if not Assigned(FPhoneBook) then
RefreshPhoneBook;
for I := 0 to FPhoneBook.Count - 1 do
if FPhoneBook[I] = RasConn[0].szEntryName then
begin
FConnection := RasConn[0].rasConn;
Result := FPhoneBook[I];
Break;
end;
end;
end;
function TJvRas32.CreateNewConnection: Boolean;
begin
if RasAvailable then
Result := FRasCreatePhonebookEntry(FPHandle, nil) = 0
else
Result := False;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -