down一个有源代码的Ras控件, 增加如下方法:
function TRas.SetPppEntry(const Name, PhoneNumber: string; wDeviceIndex: Word = 0;
const IP: string = ''; const UserName: string = ''; const Password: string = ''): Boolean;
var
RasEntry: TRasEntry;
RasDialParams: TRasDialParams;
begin
Result := False;
if DeviceNameList.Count < 1 then
begin
ShowMessage('没有安装调制解调器');
Exit;
end;
FillChar(RasEntry, SizeOf(TRasEntry), 0);
with RasEntry do
begin
dwSize := SizeOf(TRasEntry);
dwfOptions := RASEO_ModemLights or RASEO_IpHeaderCompression or
RASEO_RemoteDefaultGateway or RASEO_SwCompression;
if IP <> '' then
dwfOptions := dwfOptions or RASEO_SpecificIpAddr;
dwfNetProtocols := RASNP_Ip;
dwFramingProtocol := RASFP_Ppp;
StrPCopy(szLocalPhoneNumber, PhoneNumber);
StrPCopy(szDeviceName, DeviceNameList[wDeviceIndex]);
StrPCopy(szDeviceType, DeviceTypeList[wDeviceIndex]);
end;
with RasDialParams do
begin
FillChar(RasDialParams, SizeOf(RasDialParams), #0);
dwSize := SizeOf(TRasDialParams);
StrPCopy(szEntryName, Name);
StrPCopy(szPhoneNumber, PhoneNumber);
StrPCopy(szUserName, UserName);
StrPCopy(szPassword, Password);
end;
FLastError := RasSetEntryProperties(nil, PChar(Name),
@RasEntry, SizeOf(TRasEntry), nil, 0);
Result := (FLastError = 0);
if (UserName <> '') and (Password <> '') then
Result := Result and (RasSetEntryDialParams(nil, RasDialParams, False) = 0);
end;