SysCfg.pas
上传用户:hbtcygglw
上传日期:2007-01-07
资源大小:281k
文件大小:4k
- unit SysCfg;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Spin, StdCtrls, Buttons,FileCtrl;
- type
- TSysCfgDlg = class(TForm)
- btnOk: TBitBtn;
- BitBtn2: TBitBtn;
- GroupBox1: TGroupBox;
- Label7: TLabel;
- edLocalPort: TSpinEdit;
- GroupBox3: TGroupBox;
- Label5: TLabel;
- edPath: TEdit;
- btnBrowOICQPath: TSpeedButton;
- cbAutoLaunch: TCheckBox;
- Label3: TLabel;
- edSrvAddr: TEdit;
- Label4: TLabel;
- edSrvPort: TSpinEdit;
- Label1: TLabel;
- edDBFPath: TEdit;
- btnBrowDBFPath: TSpeedButton;
- OpenDlg: TOpenDialog;
- procedure btnBrowOICQPathClick(Sender: TObject);
- procedure btnBrowDBFPathClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- class function Execute:Boolean;
- class function LoadConfig(var path,dbfPath,SrvIp: String;var SrvPort, LocalPort: WORD;var AutoLaunch:Boolean):Boolean;
- class function SaveConfig(path,dbfPath,SrvIp:String;SrvPort,LocalPort:WORD;AutoLaunch:Boolean):Boolean;
- end;
- const
- IniPath='SpyCfg2.Dat';
- var
- GOICQPath,GDBFPath,GSrvIp:String;
- GSrvPort,GLocalPort:Word;
- GAutoLaunch:Boolean;
- implementation
- uses IpHdr;
- {$R *.DFM}
- //uses info, Main;
- { TSysCfgDlg }
- class function TSysCfgDlg.Execute: Boolean;
- begin
- with TSysCfgDlg.Create(Application) do
- begin
- if(TSysCfgDlg.LoadConfig(GOICQPath,GDBFPath,GSrvIp,GSrvPort,GLocalPort,GAutoLaunch))then
- begin
- edPath.Text:=GOICQPath;
- edDBFPath.Text:=GDBFPath;
- edSrvAddr.Text:=GSrvIp;
- edSrvPort.Value:=GSrvPort;
- edLocalPort.Value:=GLocalPort;
- cbAutoLaunch.Checked:=GAutoLaunch;
- end;
- Result:=(ShowModal=mrOk);
- if(Result)then
- begin
- GSrvIp:=edSrvAddr.Text;
- GSrvPort:=edSrvPort.Value;
- GLocalPort:=edLocalPort.Value;
- GOICQPath:=edPath.text;
- GDBFPath:=edDBFPath.Text;
- GAutoLaunch:=cbAutoLaunch.Checked;
- TSysCfgDlg.SaveConfig(GOICQPath,GDBFPath,GSrvIp,GSrvPort,GLocalPort,GAutoLaunch);
- end;
- Free;
- end;
- end;
- procedure TSysCfgDlg.btnBrowOICQPathClick(Sender: TObject);
- var
- path:string;
- begin
- if(SelectDirectory('请选择OICQ安装的路径','',path))then
- begin
- edPath.Text:=path;
- end;
- end;
- {$I-}
- class function TSysCfgDlg.LoadConfig(var path,dbfPath,SrvIp: String;
- var SrvPort, LocalPort: WORD;var AutoLaunch:Boolean): Boolean;
- var
- f:TextFile;
- s:string;
- begin
- if(not FileExists(IniPath))then
- begin
- Result:=False;
- Exit;
- end;
- AssignFile(f,IniPath);
- Reset(f);
- try
- if(not eof(f))then ReadLn(f,path);
- if(not eof(f))then ReadLn(f,dbfPath);
-
- if(not eof(f))then ReadLn(f,s);
- SrvIp:=s;
- if(not eof(f))then ReadLn(f,s);
- SrvPort:=StrToInt(s);
- if(not eof(f))then ReadLn(f,s);
- LocalPort:=StrToInt(s);
- if(not eof(f))then ReadLn(f,s);
- AutoLaunch:=(s='T');
- Result:=True;
- except
- Result:=False;
- end;
- CloseFile(f);
- end;
- {$I+}
- class function TSysCfgDlg.SaveConfig(path,dbfPath,SrvIp: String;
- SrvPort, LocalPort: WORD;AutoLaunch:Boolean): Boolean;
- var
- f:TextFile;
- begin
- AssignFile(f,ExtractFilePath(Application.ExeName)+IniPath);
- Rewrite(f);
- try
- WriteLn(f,path);
- WriteLn(f,dbfPath);
- WriteLn(f,SrvIp);
- WriteLn(f,IntToStr(SrvPort));
- WriteLn(f,IntToStr(LocalPort));
- if(AutoLaunch)then WriteLn(f,'T')
- else WriteLn(f,'F');
- Result:=True;
- except
- On e:Exception do
- begin
- Result:=False;
- ShowMessage(E.Message);
- end;
- end;
- CloseFile(f);
- end;
- procedure TSysCfgDlg.btnBrowDBFPathClick(Sender: TObject);
- begin
- if(OpenDlg.Execute)then
- begin
- edDBFPath.Text:=OpenDlg.FileName;
- end;
- end;
- end.