📄 connect.~pas
字号:
unit connect;
interface
uses
//Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
// Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons,registry;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls, ComCtrls, ImgList, ExtCtrls, Registry, Spin, Db,
DBClient, variants;
type
Tfm_SerConfig = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edt_host: TEdit;
Label2: TLabel;
Label3: TLabel;
Edt_ip: TEdit;
Edt_port: TEdit;
Button1: TButton;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
StatusBar1: TStatusBar;
procedure BitBtn1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure WriteToReg(const bappHost,bappIp,aPort:string);
{ Private declarations }
public
{ Public declarations }
end;
var
fm_SerConfig: Tfm_SerConfig;
Connected: boolean= false; //代表是否连接成功
implementation
uses netlist, data;
{$R *.dfm}
procedure Tfm_SerConfig.BitBtn1Click(Sender: TObject);
begin
if ((Edt_host.Text='') or (Edt_host.Text=null))
and((Edt_ip.Text='') or (Edt_host.Text=null)) then
begin
application.MessageBox('请输入服务器和IP','输入错误',
mb_iconinformation + mb_defbutton1);
exit;
end;
try
strtoint(edt_Port.text);
except
Application.MessageBox('请输入正确的端口号', '输入错误..', mb_iconinformation + mb_defbutton1);
exit;
end;
statusbar1.Panels[0].Text:='正在连接服务器,pleale wait';
statusbar1.Refresh;
screen.Cursor:=crHourGlass;
fm_data.Socket.Connected:=false;
fm_data.Socket.Host:=edt_host.Text;
fm_data.Socket.Address:=edt_ip.Text;
fm_data.Socket.Port:=strtoint(edt_port.Text);
try
screen.Cursor:=crdefault;
fm_data.Socket.Connected:=true;
application.MessageBox('连接成功','图书管理系统', mb_iconinformation + mb_defbutton1);
connected:=true;
except
screen.Cursor:=crdefault;
application.MessageBox('连接失败','图书管理系统',mb_iconinformation+mb_defbutton1);
connected:=false;
end;
//连接成功向注册表里写入应用服务器配置信息
WriteToReg(edt_Host.Text, edt_IP.Text, edt_Port.Text);
close;
end;
procedure Tfm_SerConfig.Button1Click(Sender: TObject);
begin
edt_ip.Clear;
edt_host.Text:= NetExecute(TFm_NetList);
end;
procedure Tfm_SerConfig.WriteToReg(const bappHost,bappIp,aPort:string);
var
reg:Tregistry;
begin
reg:=Tregistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if not reg.OpenKey('\Software\pz',false) then //如果可以创建目录
begin
reg.CreateKey('\Software\pz');
reg.OpenKey('\Software\pz',false);
end;
reg.WriteString('host',bapphost);
reg.WriteString('ip',bappip);
reg.WriteString('port',aport);
reg.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -