如何取得BDE中的配置信息(100分)

  • 主题发起人 主题发起人 wcj_moneybags
  • 开始时间 开始时间
W

wcj_moneybags

Unregistered / Unconfirmed
GUEST, unregistred user!
请教:
在BDE中配置了一个联接oracle8数据库的别名"ALIAS_ORA8",现摘录配置信息如下:

TYPE= ORACLE
NET PROTOCOL= TNS
SERVER NAME= INFO_MANAGER
USER NAME= USER1
...

请问应如何取得其中的配置信息项的内容,如取得"SERVER NAME"的
值"INFO_MANAGER"。谢谢!!!
 
请参考一下http://www.delphibbs.com/delphibbs/dispq.asp?lid=470093.
其实可以从TSession或Register表中取得相关的数据。
 
var
MyStringList :TStringList;
begin
MyStringList := TStringList.Create;
try
Session.GetAliasParams('zyzgzfbt_ora',MyStringList);
{ fill a list box with driver names for the user to select from }
ListBox1.Items := MyStringList;
finally
MyStringList.Free;
end;
listbox1中有你要的数据,再取出即可
 
unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DBTables, Buttons, dxCntner, dxEditor,
dxEdLib;

type
TMainForm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Bevel1: TBevel;
Session1: TSession;
EditStyleController: TdxEditStyleController;
DatabaseNameEdit: TdxEdit;
HostNameEdit: TdxEdit;
ChashEdit: TdxEdit;
ServerNameEdit: TdxEdit;
SQLTypeEdit: TdxEdit;
UserNameEdit: TdxEdit;
DeaultSpeedButton: TSpeedButton;
ApplySpeedButton: TSpeedButton;
SaveSpeedButton: TSpeedButton;
CloseSpeedButton: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CloseSpeedButtonClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DeaultSpeedButtonClick(Sender: TObject);
procedure SaveSpeedButtonClick(Sender: TObject);
procedure ApplySpeedButtonClick(Sender: TObject);
procedure HostNameEditChange(Sender: TObject);
private
MyList:TStringList;
BDEInfoList:TStringList;
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
begin
MyList:=TStringList.Create;
BDEInfoList:=TStringList.Create;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
MyList.Free;
BDEInfoList.Free;
end;

procedure TMainForm.CloseSpeedButtonClick(Sender: TObject);
begin
MainForm.Close;
end;

procedure TMainForm.FormShow(Sender: TObject);
begin
try
Session1.GetAliasParams('DrugStore',BDEInfoList);
finally
DatabaseNameEdit.Text:=BDEInfoList.Values['DATABASE NAME'];
HostNameEdit.Text:=BDEInfoList.Values['HOST NAME'];
ChashEdit.Text:=BDEInfoList.Values['SCHEMA CACHE DIR'];
ServerNameEdit.Text:=BDEInfoList.Values['SERVER NAME'];
SQLTypeEdit.Text:=BDEInfoList.Values['SQLQRYMODE'];
UserNameEdit.Text:=BDEInfoList.Values['USER NAME'];
end;
end;

procedure TMainForm.DeaultSpeedButtonClick(Sender: TObject);
begin
DatabaseNameEdit.Text:='DrugStore';
HostNameEdit.Text:='server';
ChashEdit.Text:='C:/Program Files/Common Files/Borland Shared/BDE';
ServerNameEdit.Text:='server';
SQLTypeEdit.Text:='server';
UserNameEdit.Text:='sa';
end;

procedure TMainForm.SaveSpeedButtonClick(Sender: TObject);
begin
SaveSpeedButton.Enabled:=False;
Session1.SaveConfigFile;
end;

procedure TMainForm.ApplySpeedButtonClick(Sender: TObject);
begin
ApplySpeedButton.Enabled:=False;

try
Session1.DeleteAlias('DrugStore');
finally
try
with MyList do
begin
Clear;
Add('DATABASE NAME='+DatabaseNameEdit.Text);
Add('HOST NAME='+HostNameEdit.Text);
Add('SCHEMA CACHE DIR='+ChashEdit.Text);
Add('SERVER NAME='+ServerNameEdit.Text);
Add('SQLQRYMODE='+SQLTypeEdit.Text);
Add('USER NAME='+UserNameEdit.Text);
end;
Session1.AddAlias('DrugStore','MSSQL',MyList);
Session1.Active:=True;
finally

end;
end;
SaveSpeedButton.Enabled:=True;
end;

procedure TMainForm.HostNameEditChange(Sender: TObject);
begin
if ApplySpeedButton.Enabled then exit;

ApplySpeedButton.Enabled:=True;
end;

end.
 
SoftBoy您好,谢谢您的回复。我想不使用ListBox控件(因为界面上不容许出现这个控)
而直接通过代码来访问到配置参数。
 
这个listbox里取出的是一个别名的所有配置项,你可以根据你程序的需要,而取值啊,用
listbox就是为了有所取舍,其实你对MyStringList操作也是一样的。
 
接受答案了.
 
后退
顶部