先申明
public
slInfo : Tconn;
sltestInfo:Tconn;
procedure SetDBInfo(const ci: integer);
procedure Tfrm_Select_DB.SetDBInfo(const ci: integer);
begin
info:=nil;
case ci of
0: info := @slInfo;
1: info := @slInfo;
end;
try
with dm.connection do
begin
AliasName := info^.AliasName;
DatabaseName := info^.DatabaseName;
Params.Add('USER NAME=' + info^.UserName);
Params.Add('PASSWORD=' + info^.Password);
end;
except
。。。。
end;
end;
procedure Tfrm_Select_DB.FormCreate(Sender: TObject);
var
iindex:integer;
begin
if (iindex>CB_SDB.Items.Count-1) or (iindex<0) then
begin
CB_SDB.ItemIndex := 0;
end
else
CB_SDB.ItemIndex := iindex;
connection:=false;
with slInfo do
begin
AliasName := '';
DatabaseName := ''
UserName := '';
Password := '';
end;
with sltestInfo do
begin
AliasName := '';
DatabaseName := ''
UserName := '';
Password := '';
end;
end;
procedure Tfrm_Select_DB.bt_okClick(Sender: TObject);
procedure updateDBName;
var
i:integer;
begin
with dm do
begin
for i:=0 to ComponentCount - 1 do
if Components is TDBDataSet then
(Components as TDBDataSet).DataBaseName :=gDataBaseName;
end;
end;
begin
if not Assigned(dm) then
dm := Tdm.Create(application);
try
with dm.connection do
begin
close;
Params.Clear;
SetDBInfo(CB_SDB.ItemIndex);
Open;
WriteToIni(CB_SDB.ItemIndex);
end;
gDataBaseName:= info^.DatabaseName;
updateDBName;
Connected:=true;
close;
except
application.Terminate;
end;
end;