本文參考了各路大神文章,在這裏表示感謝,項目要求連接oracle數據庫,不安裝oracle客戶端,同時支持32位和64位應用程序,試驗多次整理而成。
1、執行
2、把$\UniDAC55src\Bin\Delphi21\Win32\目錄下*.bpl
複製到c:\Users\Public\Documents\Embarcadero\Studio\15.0\Bpl\下。
3、把
操作路徑爲:tools->options->environment options->Delphi options->library,在library path中輸入。
4、打開Delphi XE7,
Component->Install Packages
安裝c:\Users\Public\Documents\Embarcadero\Studio\15.0\Bpl\dclunidac210.bpl。
6、規劃工程文件路徑,建立pas、dcu、thirdparty_unidac\dcu,工程選項設置如下:
64位平臺同樣的設置,對於工程中新增的單元文件保存到pas目錄中。
7、編譯需要添加$\UniDAC55src\Lib\Delphi21\Win32\如下dcu
到工程目錄thirdparty_unidac\dcu下,
OraCallUni.dcu
OraClassesUni.dcu
OracleUniProvider.dcu
OraConnectionPoolUni.dcu
OraConnectionStringUni.dcu
OraConstsUni.dcu
OraDataTypeMapUni.dcu
OraDateTimeUni.dcu
OraErrorUni.dcu
OraIntervalUni.dcu
OraNumberUni.dcu
OraObjectsUni.dcu
OraParserUni.dcu
OraScriptProcessorUni.dcu
OraServicesUni.dcu
OraSQLGeneratorUni.dcu
7、當編譯32位程序時,拷貝
選擇不同的64bit目標平臺添加命令:
copy ..\doc\oranet\x64\oranetuni.dcu .\thirdparty_unidac\dcuoranetuni.dcu到project options->build events->pre-build events->commands
選擇不同的32bit目標平臺添加命令:
copy ..\doc\oranet\x86\oranetuni.dcu .\thirdparty_unidac\dcuoranetuni.dcu到
project options->build events->pre-build events->commands
8、新建vcl工程,打開窗口,在tool palette最下面找到UniDAC Providers打開,
加入TOracleUniProvider控件,打開UniDAC,加入TUniconnection,雙擊控件設置provider爲oracle,設置options->Direct=true。
測試代碼:
UniConnection1.SpecificOptions.Values[‘ConnectionTimeOut’] := ‘3’;
UniConnection1.server := ‘192.168.37.130:1521:orcl’;
UniConnection1.username := ‘hello’;
UniConnection1.password := ‘hello’;
try
UniConnection1.Connect;
ShowMessage(‘ok’);
except
on e: exception do
begin
ShowMessage(e.message);
end;
end;