📄 main.pas
字号:
CurrConnection := '' ;
StateChanged (self) ; // update panel
Status.Panels[1].Text := '连接中断' ;
beep ;
exit ;
end ;
Status.Panels[1].Text := '连接成功' ;
end;
procedure TMainForm.CreateRasConnClick(Sender: TObject);
begin
Status.Panels[1].Text := '' ;
if RAS.CreatePhonebook <> 0 then
Status.Panels[1].Text := RAS.StatusStr
else
begin
RAS.GetPhoneBookEntries; // get new list of connections
ConnList.Items.Assign (RAS.PhoneBookEntries); // display it
if ConnList.Items.Count <> 0 then ConnList.ItemIndex := 0 ; // set first
ConnListClick (self) ; // get connection info
end ;
end;
procedure TMainForm.DeleteRasConnClick(Sender: TObject);
begin
Status.Panels[1].Text := '' ;
if ConnList.ItemIndex = -1 then exit ;
RAS.EntryName := ConnList.Items [ConnList.ItemIndex]; // Connection name
if RAS.DeletePhonebook <> 0 then
Status.Panels[1].Text := RAS.StatusStr
else
begin
RAS.GetPhoneBookEntries; // get new list of connections
ConnList.Items.Assign (RAS.PhoneBookEntries); // display it
if ConnList.Items.Count <> 0 then ConnList.ItemIndex := 0 ; // set first
ConnListClick (self) ; // get connection info
end ;
end;
procedure TMainForm.SetupRasClick(Sender: TObject);
begin
Status.Panels[1].Text := '' ;
if ConnList.ItemIndex = -1 then exit ;
RAS.EntryName := ConnList.Items [ConnList.ItemIndex]; // Connection name
if RAS.EditPhonebook <> 0 then // display Dialog
Status.Panels[1].Text := RAS.StatusStr ;
end;
procedure TMainForm.ConnListClick(Sender: TObject);
begin
if ConnList.ItemIndex = -1 then exit ;
RAS.EntryName := ConnList.Items [ConnList.ItemIndex]; // Connection name
if RAS.GetDialParams = 0 then // get connection parameters
begin
if RAS.GetEntryProperties = 0 then
begin
{ DeviceName.Caption := '设备名称: ' + RAS.DeviceName ;
DeviceType.Caption := '设备类型: ' + RAS.DeviceType ;
DevicePort.Caption := '设备端口: ' + RAS.DevicePort ;
ConnPhone.Caption := '电话号码: ' + RAS.PhoneNumber ;
ConnCanonical.Caption := '正式号码: ' + RAS.PhoneCanonical ;
}end ;
Timer.Enabled := true ; // not until RAS installed
end
else
Status.Panels[1].Text := RAS.StatusStr ;
end;
// event handler called by TRAS when connection status changes
procedure TMainForm.StateChanged(Sender: TObject);
var
info: string ;
begin
if CurrConnection = '' then
begin
info := 'DUN: 离线';
AdslDisConnect.Enabled := false;
ViewRemoteVideo.Enabled := false;
end
else
begin
info := 'DUN: ' + CurrConnection + ' - ' + RAS.StatusStr ;
Status.Panels[0].Text := info ;
AdslDisConnect.Enabled := true;
ViewRemoteVideo.Enabled := true;
end
end;
procedure TMainForm.TimerTimer(Sender: TObject);
var
CMDStr:string;
begin
// see if any connections are open
RAS.GetConnections ; // check for active connections
if Ras.Connections.Count = 0 then // no active connections
begin
OnlineFlag := false ;
if CurrConnection <> '' then // just gone offline
begin
CurrConnection := '' ;
RAS.IntDisconnect ; // disconnect, but ignore errors
RAS.ResetPerfStats ; // clear stats for next connection
StateChanged (self) ;
end
end
else
begin // see if new connection
if CurrConnection <> RAS.Connections.EntryName (0) then
begin
CurrConnection := RAS.Connections.EntryName (0) ;
RAS.ReOpen (0) ; // allow RAS to use this connection
end ;
RAS.CurrentStatus ; // triggers StateChanged event
if (RAS.ConnectState = RASCS_Connected) then
begin
RAS.GetPerfStats ; // get performance info
if NOT OnlineFlag then
begin
OnlineFlag := true ;
{
// connections speed not available on NT
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
ConnSpeed.Caption := 'Speed: ' +
IntToStr (RAS.StatsConn) + ' bps' ;
// dynamic IP addresses
if RAS.GetIPAddress = 0 then IPAddr.Caption := RAS.ClientIP + ' > ' + RAS.ServerIP ;
}
//adsl connect to internet
if NOT AdslOnlineFlag then
begin
//Set User Info
NMHTTPADSL.HeaderInfo.UserId := AdslUser;
NMHTTPADSL.HeaderInfo.Password := AdslPwd;
NMHTTPADSL.InputFileMode := false;
//Adsl connect
CMDStr := 'http://' + AdslAddr + '/doc/P_ppp_c.htm?WINDWEB_URL=/doc/P_ppp_c.htm&LIST=VC-----STATUS--------&PPP_virtual_circuit=1&PPP_Action=0';
//GetInfo
NMHTTPADSL.Get(CMDStr);
Status.Panels[0].Text := '远程Adsl设备正在连接......' ;
end
else
AdslOnlineFlag := true;
end ;
end ;
end ;
end;
procedure TMainForm.GetRasEntriesClick(Sender: TObject);
begin
OnlineFlag := false ;
CurrConnection := '' ; // no active connection, yet
RAS := TRAS.Create (Self) ; // create TRAS component
RAS.OnStateChanged := StateChanged ; // install event handler
if RAS.TestRAS then
begin
// get list of connections
RAS.GetPhoneBookEntries;
ConnList.Items.Assign (RAS.PhoneBookEntries); // display it
if ConnList.Items.Count <> 0 then ConnList.ItemIndex := 0 ; // set first
// initial settings
ConnListClick (self) ; // get connection info
Timer.Enabled := true ;
StateChanged (self) ; // initial status panel
end
else
begin
ConnList.Items.Add (RAS.StatusStr) ; // no RAS available
Status.Panels[1].Text := RAS.StatusStr ;
end ;
end;
procedure TMainForm.GetAdslIPAddr(Sender: TObject);
var
CMDStr:string;
wsStr:string;
index:integer;
Len:integer;
Addrstr:string;
begin
//Set User Info
NMHTTPADSL.HeaderInfo.UserId := AdslUser;
NMHTTPADSL.HeaderInfo.Password := AdslPwd;
NMHTTPADSL.InputFileMode := false;
//Get Adsl addr Info
CMDStr := 'http://' + AdslAddr + '/doc/P_ws_c.htm';
NMHTTPADSL.Get(CMDStr);
wsStr := NMHTTPADSL.Body;
index := pos('ppp1","',wsstr);
Addrstr:= copy(wsstr,index+7,20);
Len := pos('"',Addrstr)-1;
AdslIP:= copy(Addrstr,0,Len);
Status.Panels[0].Text := '远程IP: ' + AdslIP;
end;
procedure TMainForm.ViewRemoteVideoClick(Sender: TObject);
var
CMDStr:string;
begin
GetAdslIPAddr(self);
RAS.DisConnect();
CMDStr := 'vcnt1.exe ' + AdslIP;
WinExec(PChar(CMDStr),SW_SHOW);
end;
procedure TMainForm.AdslDisConnectClick(Sender: TObject);
var
CMDStr:string;
begin
//Set User Info
NMHTTPADSL.HeaderInfo.UserId := AdslUser;
NMHTTPADSL.HeaderInfo.Password := AdslPwd;
//GetInfo
CMDStr := 'http://' + AdslAddr + '/doc/P_ppp_c.htm?WINDWEB_URL=/doc/P_ppp_c.htm&LIST=VC-----STATUS--------&PPP_virtual_circuit=1&PPP_Action=1';
NMHTTPADSL.Get( CMDStr);
Status.Panels[0].Text := '正在断开远程Adsl设备......' ;
RAS.DisConnect();
end;
procedure TMainForm.BitBtnExitClick(Sender: TObject);
begin
with Application do
begin
NormalizeTopMosts;
if MessageBox('确定真的要退出系统吗?','退出系统',MB_OKCANCEL) = IDOK then
Close
else
RestoreTopMosts;
end;
end;
procedure TMainForm.ReadSiteInfo(Sender: TObject);
var
RecCount:integer;
FileName:string;
begin
FileName := 'comm.cfg';
// if OpenSiteInfo.Execute then FileName:=OpenSiteInfo.FileName;
if not CheckFileValidity(FileName,RecCount) then Exit;
GetSiteInfoFromFile(FileName,RecCount);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -