delphi7讀取ini配置連線oracle10G

2021-06-05 03:38:42 字數 1464 閱讀 6130

近期在學delphi,需要走配置連線oracle資料庫,但是網上好多方法都是沒有帶ip位址的。最後找了好久終於找到了,不過忘了在**找到的了,分享給大家吧!

需要引入inifiles 建立form時呼叫

在user 內加入inifiles

procedure tform1.formcreate(sender: tobject);

const

connstr = 'provider=oraoledb.oracle.1;password=%s;persist security info=true;user id=%s;data source=(description = (address_list = (address = (protocol = tcp) (host = %s)(port = %s)))(connect_data = (service_name = %s)))';

varinifile : tinifile;

ip, port, sid, username, password, filename, filepath : string;

begin

filepath := extractfilepath(paramstr(0));

filename := filepath + 'dbconfig.ini';

if fileexists(filename) then

begin

inifile := tinifile.create(filename);

ip := inifile.readstring('database', 'ip', '127.0.0.1');

port := inifile.readstring('database', 'port', '1521');

sid := inifile.readstring('database', 'sid', 'orcl');

username := inifile.readstring('database', 'username', 'admin');

password := inifile.readstring('database', 'password', 'admin');

form1.adoconnection1.connectionstring := format(connstr, [password, username, ip, port, sid]);

endelse

showmessage('沒有找到dbconfig.ini檔案,請核對!');

end;

ini檔案內容

[database]

ip=127.0.0.1

port=1521

sid=orcl

password=admin

username=admin

//注意點:extractfilepath(paramstr(0) + 'dbconfig.ini');我這裡這樣寫貌似不行,這樣得到的結果沒有加後面的檔名

delphi讀取 ini配置檔案

因工作需要最近開始學習delphi,可能是因為現在不熱門,網上搜好多問題和資料都搜不到或者不完全對症,整理記錄一下自己遇到的一些問題。在.ini檔案中寫資料庫鏈結字串和一些字段,這樣一些基本資料修改起來比較方便,下面來說一下delphi中讀取.ini檔案的過程。uses windows,messag...

Delphi7遠端除錯

自己的開發機器稱為主機,執行程式的機器稱為目標機 一 在主機編譯執行程式 1 project options linker中的exe and dll options選項組中的include remote debug symbols打上勾,這樣就可以生成rsm為副檔名的檔案,該檔名稱於你的專案同名。2...

Delphi7 動態陣列

初學delphi,感覺.這感覺就是寫 太費勁了,已經習慣了c 那種信手拈來,不能說pascal不適應只能說還是費勁,可能是d7太老了,也可能是我還沒有上道兒,就這麼著吧,下面簡單的寫倆函式作為參考,修改修改可以當c 中的list 用arr array of string procedure add ...