在Delphi中使用RAS实现对系统拨号的控制
在Delphi中使用RAS实现对系统拨号的控制
在企业应用中有时候希望能在程序中实现对拨号网络的控制,以实现自动拨号、自动断开网络。在尝试了多种方式之后,认为RAS是一种比较稳定的方式。在google了网上一些资料后,现整理如下:
一、首先需要有个针对RAS的头文件定义,Ras.pas代码如下
{* Copyright (c) 1992-1995, Microsoft Corporation, all rights reserved
**
** ras.h
** Remote Access external API
** Public header for external API clients
*}
{ Delphi conversion by Davide Moretti <dmoretti@iper.net> }
{ Note: All functions and structures defaults to Ansi. If you want to use
Unicode structs and funcs, use the names ending with 'W' }
unit Ras;
interface
uses Windows, Messages;
const
{ These are from lmcons.h }
DNLEN = 15; // Maximum domain name length
UNLEN = 256; // Maximum user name length
PWLEN = 256; // Maximum password length
NETBIOS_NAME_LEN = 16; // NetBIOS net name (bytes)
RAS_MaxDeviceType = 16;
RAS_MaxPhoneNumber = 128;
RAS_MaxIpAddress = 15;
RAS_MaxIpxAddress = 21;
{ Note: you must define WINVER31 before compiling this unit to get the sizes
for the 3.x version of RAS. The default is for Windows 95 and NT 4.0 }
{$IFDEF WINVER31}
{Version 3.x sizes }
RAS_MaxEntryName = 20;
RAS_MaxDeviceName = 32;
RAS_MaxCallbackNumber = 48;
{$ELSE}
{Version 4.x sizes }
RAS_MaxEntryName = 256;
RAS_MaxDeviceName = 128;
RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;
{$ENDIF}
type
LPHRasConn = ^THRasConn;
THRasConn = Longint;
{* Identifies an active RAS connection. (See RasEnumConnections)
*}
LPRasConnW = ^TRasConnW;
TRasConnW = record
dwSize: Longint;
hrasconn: THRasConn;
szEntryName: Array[0..RAS_MaxEntryName] of WideChar;
{$IFNDEF WINVER31}
szDeviceType: Array[0..RAS_MaxDeviceType] of WideChar;
szDeviceName: Array[0..RAS_MaxDeviceName] of WideChar;
{$ENDIF}
end;
LPRasConnA = ^TRasConnA;
TRasConnA = record
dwSize: Longint;
相关文档:
//定义MyClass
TMyClass = class
GUID: string;
Name: string;
bSex: Boolean;
Tel : string;
end;
//取值
var
obj: TMyClass;
begin
obj := TMyClass.Create;
with Memo1.Lines do
begin
Add('对象大小:' + IntToStr(obj.InstanceSize));
Add('对象所在地址:'+ ......
1. 命令的接收者
{《HeadFirst设计模式》之命令模式 }
{ 本单元中的类为命令的接收者 }
{ 编译工具 :Delphi7.0 }
{ 联系方式 :xshlife@163.com }
unit uReceiveObject;
interface
type
TLight = class(TObject)
private
FLocation: String;
public
constru ......
没有应用状态模式的代码
1. 工程文件
program Project1;
{$APPTYPE CONSOLE}
uses
uGumballMachine in 'uGumballMachine.pas';
var
aGumballMachine: TGumballMachine;
begin
aGumballMachine := TGumballMachine.Create(5);
aGumballMachine.InsertQuarter;
aGumballMachine.TurnCrank;
Writeln; ......
一、在Delphi7中连接MS SQL Server 2000的方法。
刚开始时界面如下:添加4个控件。
设置控件属性过程:
1、ADOConnection1设置
1)双击ADOConnection1,进行设置连接字符串(作用是:选取连接驱动方式和连接的数据库设置)。过程如下图所示:
2、ADOQuery1设置:
1)ADOQuery1.connection属性为ADOConnection1; ......