unit alias;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Registry, filectrl;
type
TForm1 = class(TForm)
alias: TEdit;
host: TEdit;
port: TEdit;
sid: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
ls_reg_path: string;
path: string;
filename: string;
fid: TextFile;
ss:string;
begin
path := '';
ls_reg_path := '/Software/ORACLE';
with TRegistry.Create do
begin
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(ls_reg_path,false) then
begin
path:=ReadString('NET80');
if path = '' then
path:=ReadString('NETWORK');
end;
finally
CloseKey ;
free;
end;
end;
if path = '' then
begin
application.MessageBox('请确认已安装Oracle7.0以上数据库','错误',MB_OK);
abort;
end;
path := path + '/ADMIN';
filename := path + '/Tnsnames.ora';
assignfile(fid,filename);
ss := #13#10 + alias.Text + '.WORLD = ' + #13#10;
ss := ss + ' (DESCRIPTION = ' + #13#10;
ss := ss + ' (ADDRESS = (PROTOCOL = TCP)(HOST = ' +host.text+')(PORT = '+port.text+')) ' + #13#10;
ss := ss + ' (CONNECT_DATA = (SID = ' + sid.Text + ')) ' + #13#10;
ss := ss + ' ) ' + #13#10;
append(fid);
writeln(fid,ss);
Flush(fid);
CloseFile(fid);
end;
end.