dbexpress te sqlconnection nesnesindeki connoctionların list
Forum kuralları
Forum kurallarını okuyup, uyunuz!
Forum kurallarını okuyup, uyunuz!
dbexpress te sqlconnection nesnesindeki connoctionların list
mrb.
dbexpress te sqlconnection nesnesindeki connoctionların listsini ve parametrelerini nasıl görebilirim ?
yardımlarınız için şimdiden teşekkür ederim. iyi çalışmalar
dbexpress te sqlconnection nesnesindeki connoctionların listsini ve parametrelerini nasıl görebilirim ?
yardımlarınız için şimdiden teşekkür ederim. iyi çalışmalar
Eğer datamodül kullanıyorsan tüm komponentleri sırasıyla kontrol edip sql connection ' a bağlı mı kontrolü yaptırabilirsin. Bunun sonucunda komponentin tipine göre işlem yaparsın.
Kod: Tümünü seç
for idx := 0 to Self.ComponentCount -1 do
begin
if Self.Components[idx] is TSQLDataset then
begin
//burada istediğin kontrolü yaparsın. diğerlerini de ayrı if'lerle kontrol et
end;
end;
anlatmak istediğimi tam anlamıyla anlatamadım . şimdi database lere bağlantı ismi var
onlara ait bağlantı parametreleri.
bir örneğini netten buldum aşayağıya ekliyorum umarım faydası olur.
onlara ait bağlantı parametreleri.
bir örneğini netten buldum aşayağıya ekliyorum umarım faydası olur.
Kod: Tümünü seç
{*******************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ }
{ Copyright (c) 2000 Inprise Corporation }
{ }
{ DBExpress Connection Admin Interface }
{ }
{*******************************************************}
unit DBConnAdmin;
interface
uses SysUtils, Classes, IniFiles;
type
{ IConnectionAdmin }
IConnectionAdmin = interface
function GetDriverNames(List: TStrings): Integer;
function GetDriverParams(const DriverName: string; Params: TStrings): Integer;
procedure GetDriverLibNames(const DriverName: string;
var LibraryName, VendorLibrary: string);
function GetConnectionNames(List: TStrings; DriverName: string): Integer;
function GetConnectionParams(const ConnectionName: string; Params: TStrings): Integer;
procedure GetConnectionParamValues(const ParamName: string; Values: TStrings);
procedure AddConnection(const ConnectionName, DriverName: string);
procedure DeleteConnection(const ConnectionName: string);
procedure ModifyConnection(const ConnectionName: string; Params: TStrings);
procedure RenameConnection(const OldName, NewName: string);
procedure ModifyDriverParams(const DriverName: string; Params: TStrings);
end;
{ TConnectionAdmin }
TConnectionAdmin = class(TInterfacedObject, IConnectionAdmin)
private
FDriverConfig: TIniFile;
FConnectionConfig: TIniFile;
protected
{ IConnectionAdmin }
function GetDriverNames(List: TStrings): Integer;
function GetDriverParams(const DriverName: string; Params: TStrings): Integer;
procedure GetDriverLibNames(const DriverName: string;
var LibraryName, VendorLibrary: string);
function GetConnectionNames(List: TStrings; DriverName: string): Integer;
function GetConnectionParams(const ConnectionName: string; Params: TStrings): Integer;
procedure GetConnectionParamValues(const ParamName: string; Values: TStrings);
procedure AddConnection(const ConnectionName, DriverName: string);
procedure DeleteConnection(const ConnectionName: string);
procedure ModifyConnection(const ConnectionName: string; Params: TStrings);
procedure RenameConnection(const OldName, NewName: string);
procedure ModifyDriverParams(const DriverName: string; Params: TStrings);
public
constructor Create;
destructor Destroy; override;
property ConnectionConfig: TIniFile read FConnectionConfig;
property DriverConfig: TIniFile read FDriverConfig;
end;
function GetConnectionAdmin: IConnectionAdmin;
implementation
uses SqlConst, SqlExpr, DB;
{ Global Functions }
function GetConnectionAdmin: IConnectionAdmin;
begin
Result := IConnectionAdmin(TConnectionAdmin.Create);
end;
function FormatLine(const Key, Value: string): string;
begin
Result := Format('%s=%s', [Key, Value]);
end;
function GetValue(const Line: string): string;
var
ValPos: Integer;
begin
ValPos := Pos('=', Line);
if ValPos > 0 then
Result := Copy(Line, ValPos+1, MAXINT) else
Result := '';
end;
{ TODO: Put this into TIniFile }
procedure WriteSectionValues(IniFile: TIniFile; const Section: string; Strings: TStrings);
var
I: Integer;
begin
with IniFile do
begin
EraseSection(Section);
for I := 0 to Strings.Count - 1 do
WriteString(Section, Strings.Names[I], GetValue(Strings[I]));
{$IFDEF LINUX}
UpdateFile;
{$ENDIF}
end;
end;
{ TConnectionAdmin }
constructor TConnectionAdmin.Create;
var
sConfigFile:String;
begin
inherited Create;
sConfigFile := GetDriverRegistryFile(True);
if not FileExists(sConfigFile) then
DatabaseErrorFmt(SMissingDriverRegFile,[sConfigFile]);
FDriverConfig := TIniFile.Create(sConfigFile);
sConfigFile := GetConnectionRegistryFile(True);
if not FileExists(sConfigFile) then
DatabaseErrorFmt(SMissingDriverRegFile,[sConfigFile]);
FConnectionConfig := TIniFile.Create(sConfigFile);
end;
destructor TConnectionAdmin.Destroy;
begin
inherited;
FConnectionConfig.Free;
FDriverConfig.Free;
end;
procedure TConnectionAdmin.AddConnection(const ConnectionName,
DriverName: string);
var
Params: TStrings;
DriverIndex: Integer;
begin
Params := TStringList.Create;
try
GetDriverParams(DriverName, Params);
Params.Insert(0, FormatLine(DRIVERNAME_KEY, DriverName));
DriverIndex := Params.IndexOfName(GETDRIVERFUNC_KEY);
if DriverIndex <> -1 then
Params.Delete(DriverIndex);
WriteSectionValues(ConnectionConfig, ConnectionName, Params);
finally
Params.Free
end;
end;
procedure TConnectionAdmin.DeleteConnection(const ConnectionName: string);
begin
ConnectionConfig.EraseSection(ConnectionName);
end;
function TConnectionAdmin.GetConnectionNames(List: TStrings;
DriverName: string): Integer;
var
I: Integer;
begin
ConnectionConfig.ReadSections(List);
if DriverName <> '' then
begin
List.BeginUpdate;
try
I := List.Count - 1;
while I >= 0 do
begin
if AnsiCompareText(ConnectionConfig.ReadString(List[i], DRIVERNAME_KEY, ''),
DriverName) <> 0 then List.Delete(I);
Dec(I);
end;
finally
List.EndUpdate;
end;
end;
Result := List.Count;
end;
function TConnectionAdmin.GetConnectionParams(const ConnectionName: string;
Params: TStrings): Integer;
begin
ConnectionConfig.ReadSectionValues(ConnectionName, Params);
Result := Params.Count;
end;
procedure TConnectionAdmin.GetConnectionParamValues(const ParamName: string;
Values: TStrings);
begin
DriverConfig.ReadSection(ParamName, Values);
end;
function TConnectionAdmin.GetDriverNames(List: TStrings): Integer;
begin
DriverConfig.ReadSection(DRIVERS_KEY, List);
Result := List.Count;
end;
function TConnectionAdmin.GetDriverParams(const DriverName: string; Params: TStrings): Integer;
procedure RemoveEntry(const KeyName: string);
var
Index: Integer;
begin
Index := Params.IndexOfName(KeyName);
if Index > -1 then Params.Delete(Index);
end;
begin
DriverConfig.ReadSectionValues(DriverName, Params);
RemoveEntry(DLLLIB_KEY);
RemoveEntry(VENDORLIB_KEY);
Result := Params.Count;
end;
procedure TConnectionAdmin.GetDriverLibNames(const DriverName: string;
var LibraryName, VendorLibrary: string);
begin
LibraryName := DriverConfig.ReadString(DriverName, DLLLIB_KEY, '');
VendorLibrary := DriverConfig.ReadString(DriverName, VENDORLIB_KEY, '');
end;
procedure TConnectionAdmin.ModifyConnection(const ConnectionName: string;
Params: TStrings);
begin
WriteSectionValues(ConnectionConfig, ConnectionName, Params);
end;
procedure TConnectionAdmin.RenameConnection(const OldName, NewName: string);
var
Params: TStrings;
begin
Params := TStringList.Create;
try
GetConnectionParams(OldName, Params);
ConnectionConfig.EraseSection(OldName);
WriteSectionValues(ConnectionConfig, NewName, Params);
finally
Params.Free
end;
end;
procedure TConnectionAdmin.ModifyDriverParams(const DriverName: string;
Params: TStrings);
begin
WriteSectionValues(DriverConfig, DriverName, Params);
end;
end.
O zaman aşağıdaki gibi (Delphi'nin helpinden alıntıdır) ini dosyasından veri okuman gerekir sadece. Gerekli tüm bilgiler yardım dosyasında ve forumda var.
Kod: Tümünü seç
uses IniFiles;
procedure TForm1.BtnClick(Sender: TObject);
var AppIni: TIniFile;
begin
AppIni := TIniFile.Create('IniDosyasiAdi.ini');
AppIni.ReadSections(ListBox1.Items);
AppIni.ReadSection('Ports',Listbox2.Items);
AppIni.ReadSectionValues('Ports',ListBox3.Items);
AppIni.Free;
end;