這樣寫就不用管sql是7.0還是2K了
procedure TBasDM.DataModuleCreate(Sender: TObject);
var tempIni: TIniFile;
tmpServerFrm: TServerFrm;
StartForm:TStartForm;
i:Integer;
tmpList:TStringList;
IsAliasName:Boolean;
begin
IsAliasName:=false;
tmpList:= TStringList.Create;
try
Session.GetAliasNames(tmpList);
for I := 0 to tmpList.Count - 1 do
if LowerCase(tmpList[i])='wujindb' then
IsAliasName:=true;
if not IsAliasName then
Session.AddAlias('數據庫別名','MSSQL',WJDataBase.Params);
finally
tmpList.Free;
end;
if WJDataBase.Connected then
WJDataBase.Connected := False;
pubLocaOption := [loCaseInsensitive, loPartialKey];
InitDBbasefile;
with WJDataBase.Params do
begin
Values['SERVER NAME'] := curServerName;
Values['DATABASE NAME'] := curDBName;
Values['USER NAME'] := 'sa';
Values['PASSWORD'] := '';
end;
try
WJDataBase.Open;
except
// if DJShow(CON_CONNECT_FAIL,2) = 6 then
if Application.MessageBox('數據庫連接失敗,重新設置嗎?','錯誤',
MB_ICONQUESTION+MB_YESNO)=ID_YES then
begin
tmpServerFrm:=TServerFrm.Create(Application);
tmpServerFrm.ShowModal;
if tmpServerFrm.ModalResult = mrOk then
begin
curServerName := tmpServerFrm.Edit1.Text;
curDBName := tmpServerFrm.Edit2.Text;
// tempIni := TIniFile.Create(GetwinDir + 'Wujin.ini');
tempIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Wujin.ini');
tempIni.WriteString('SYSTEM', 'SERVER', curServerName);
tempIni.WriteString('SYSTEM', 'DBNAME', curDBName);
tmpServerFrm.Free;
tempIni.Free;
end;
end
else
begin
Application.Terminate;
end;
end;
StartForm:=TStartForm.Create(Application);
StartForm.Show;
StartForm.Update;
StartForm.Refresh;
StartForm.Gauge1.Progress:=0;
StartForm.Gauge1.MaxValue:=100;
StartForm.Gauge1.MinValue:=0;
For i:=1 to 100 Do
begin
Sleep(20);
StartForm.Gauge1.Progress:=StartForm.Gauge1.Progress+1;
end;
StartForm.free;
end