1 你可以独立写个动态配odbc的程序.如果用ADO的话也可以,用这个什么方法的,现
在记不得了,待会我把你找找.
2 把连的服务器(组件)名写死,让用户来输IPaddress或Host,把结果保存在.ini文件中,这样的话
每次连服务器的时候,读一下该.ini文件,如果连接错误则重新输入服务器名,这样就可以连不同机器上的服务器了
procedure linkserver(Sender:TObject;SocketConnection1: TSocketConnection);//自定义函数.
var
servername,dirname:string;
filehandle:integer;
f:textfile;
begin
getdir(0,dirname);
showmessage('服务器名不正确,请输入正确的服务器名');
if inputquery('连接服务器操作','输入服务器名:',servername) then
begin
if fileexists(dirname+'/servername.ini') then
begin
assignfile(f,dirname+'/servername.ini');
rewrite(f);
writeln(f,servername);
closefile(f);
end else
begin
filehandle:=filecreate(dirname+'/servername.ini');
fileclose(filehandle);
assignfile(f,dirname+'/servername.ini');
rewrite(f);
writeln(f,servername);
closefile(f);
end;
socketconnection1.Connected:=false;
socketconnection1.Host:=servername;
socketconnection1.LoginPrompt:=false;
try
socketconnection1.Connected:=true;
except
on E:Exceptiondo
begin
linkserver(sender,socketconnection1);
end;
end;
end else
begin
showmessage('你取消了进入系统');
halt;
end;
end;
procedure TDataModule1.SocketConnection1BeforeConnect(Sender: TObject);
var
servername,dirname:string;
filehandle:integer;
f:textfile;
begin
getdir(0,dirname);
if fileexists(dirname+'/servername.ini') then
begin
assignfile(f,dirname+'/servername.ini');
reset(f);
while not eof(f)do
begin
readln(f,servername);
end;
closefile(f);
if length(trim(servername))<=0 then
if inputquery('连接服务器操作','输入服务器名:',servername) then
begin
assignfile(f,dirname+'/servername.ini');
rewrite(f);
writeln(f,servername);
closefile(f);
end else
begin
showmessage('你取消了进入系统');
halt;
end;
end else
begin
filehandle:=filecreate(dirname+'/servername.ini');
fileclose(filehandle);
if inputquery('连接服务器操作','输入服务器名:',servername) then
begin
assignfile(f,dirname+'/servername.ini');
rewrite(f);
writeln(f,servername);
closefile(f);
end else
begin
showmessage('你取消了进入系统');
halt;
end;
end;
socketconnection1.Connected:=false;
socketconnection1.Host:=servername;
end;
procedure TDataModule1.DataModuleCreate(Sender: TObject);
begin
try
socketconnection1.Connected:=true;
except
on E:Exceptiondo
begin
if e.Message='Operation aborted' then
begin
showmessage('你取消了进入系统');
halt;
end else
begin
linkserver(sender,socketconnection1);
end;
end;
end;
end;