ChangeFileExt
RealTime_Server.ini:
[Config]
FromConStr=DBTYPE=0|SERVER=127.0.0.1|PORT=7788|DBNAME=jzxtld|USERNAME=sa|PASSWORD=admin
ToConStr=DBTYPE=0|SERVER=127.0.0.1|PORT=7788|DBNAME=jzxxsjs|USERNAME=sa|PASSWORD=admin
procedure StrToUniCon(AStr: string; UniCon: TUniConnection);
function GetDBType(i: Integer): string;
begin
case i of
:
begin
Result := 'SQL Server';
end;
:
begin
Result := 'Oracle';
end else
begin
Result := '';
end;
end;
end;
var
L: TStrings;
begin
if Trim(AStr) = '' then Exit;
if (AStr <> '') and (AStr[Length(AStr)] = '|') then system.Delete(AStr, Length(AStr), );
L := TStringList.Create;
try
L.Delimiter := '|';
L.DelimitedText := AStr;
if L.Count = then
begin
UniCon.LoginPrompt := False;
UniCon.ProviderName := GetDBType(StrToInt(L.Values['DBTYPE']));
if SameText(UniCon.ProviderName, 'Oracle') then
begin
UniCon.SpecificOptions.Clear;
UniCon.SpecificOptions.Add('Oracle.Direct=True');
UniCon.SpecificOptions.Add('Oracle.PrecisionInteger=11');
UniCon.server := L.Values['SERVER'] + ':' + L.Values['PORT'] + ':' + L.Values['DBNAME'];
end else
begin
UniCon.server := L.Values['SERVER'] + ',' + L.Values['PORT'];
UniCon.Database := L.Values['DBNAME'];
end;
UniCon.Username := L.Values['USERNAME'];
UniCon.Password := L.Values['PASSWORD'];
end;
finally
L.Free;
end;
end;
1 procedure TfmDBConectString.bt_testconnClick(Sender: TObject);
var
Con: TUniConnection;
begin
if rgDbType.ItemIndex = - then
begin
Application.MessageBox('请选择数据库类型!', '警告', MB_ICONWARNING or MB_APPLMODAL);
Exit;
end;
Con := TUniConnection.Create(nil);
try
try
StrToUniCon(Self.GetConnectXML, Con);
Con.Connect;
ShowMessage('连接成功!');
Con.Disconnect;
except
on E: Exception do
begin
ShowMessage(E.Message);
end;
end;
finally
Con.Free;
end;
end;
procedure TSyncThread.LoadFromCon(Uni: TUniConnection);
var
S:String;
begin
with TIniFile.Create(ChangeFileExt(GetModuleName(),'.ini')) do
begin
S:=ReadString('Config','FromConStr','');
if S<>'' then
begin
StrToUniCon(S,Uni);
end;
Free;
end;
end;
function TfmMain.GetToConStr: string;
begin
with TIniFile.Create(ChangeFileExt(GetModuleName(), '.ini')) do
begin
Result := ReadString('Config', 'ToConStr', '');
Free;
end;
end; procedure TfmMain.SetToConStr(const Value: string);
begin
with TIniFile.Create(ChangeFileExt(GetModuleName(), '.ini')) do
begin
WriteString('Config', 'ToConStr', Value);
Free;
end;
end;