1 |
procedure TFBClientAPI.LoadIBLibrary;
|
2 |
|
3 |
function DoLoadLibrary(LibName: string): TLibHandle;
|
4 |
begin
|
5 |
Result := LoadLibrary(PChar(LibName));
|
6 |
if Result <> NilHandle then
|
7 |
begin
|
8 |
FFBLibraryName := ExtractFileName(LibName);
|
9 |
FFBLibraryPath := ExtractFileDir(LibName);
|
10 |
end;
|
11 |
end;
|
12 |
|
13 |
var InstallDir: string;
|
14 |
dllPathName: string;
|
15 |
oldFirebirdEV: string;
|
16 |
begin
|
17 |
if IBLibrary <> NilHandle then Exit;
|
18 |
|
19 |
{First try any user override}
|
20 |
dllPathName := GetOverrideLibName;
|
21 |
if dllPathName <> '' then
|
22 |
begin
|
23 |
IBLibrary := DoLoadLibrary(dllPathName);
|
24 |
FOwnsIBLibrary := IBLibrary <> NilHandle;
|
25 |
Exit;
|
26 |
end;
|
27 |
|
28 |
{Then look in application installation directory}
|
29 |
InstallDir := ExtractFilePath(Paramstr(0)); {Using ParamStr(0) assumes windows conventions}
|
30 |
|
31 |
//First look for Firebird Embedded Server in installation dir
|
32 |
if FileExists(InstallDir + FIREBIRD_EMBEDDED) then
|
33 |
begin
|
34 |
dllPathName := InstallDir + FIREBIRD_EMBEDDED;
|
35 |
IBLibrary := DoLoadLibrary(dllPathName)
|
36 |
end
|
37 |
else
|
38 |
//Otherwise look for Firebird Client in installation dir
|
39 |
if FileExists(InstallDir + FIREBIRD_CLIENT) then
|
40 |
begin
|
41 |
//assume firebird.conf and firebird.msg in same dir
|
42 |
oldFirebirdEV := GetEnvironmentVariable('FIREBIRD');
|
43 |
SetEnvironmentVariable('FIREBIRD',PChar(InstallDir));
|
44 |
dllPathName := InstallDir + FIREBIRD_CLIENT;
|
45 |
try
|
46 |
IBLibrary := DoLoadLibrary(dllPathName)
|
47 |
finally
|
48 |
if IBLibrary = NILHandle then
|
49 |
SetEnvironmentVariable('FIREBIRD',PChar(oldFirebirdEV)); {restore}
|
50 |
end;
|
51 |
end;
|
52 |
|
53 |
// writeln('Dir = ',InstallDir);
|
54 |
{If FIREBIRD environment variable available then try this}
|
55 |
if IBLibrary = NilHandle then
|
56 |
begin
|
57 |
InstallDir := GetEnvironmentVariable('FIREBIRD');
|
58 |
if (length(InstallDir) > 0) and (InstallDir[length(InstallDir)] <> DirectorySeparator) then
|
59 |
InstallDir += DirectorySeparator;
|
60 |
if (InstallDir <> '') and FileExists(InstallDir + FIREBIRD_CLIENT) then
|
61 |
begin
|
62 |
//assume firebird.conf and firebird.msg in same dir
|
63 |
dllPathName := InstallDir + FIREBIRD_CLIENT;
|
64 |
IBLibrary := DoLoadLibrary(dllPathName)
|
65 |
end
|
66 |
else
|
67 |
if (InstallDir <> '') and FileExists(InstallDir + 'bin' + DirectorySeparator + FIREBIRD_CLIENT) then
|
68 |
begin
|
69 |
dllPathName := InstallDir + FIREBIRD_CLIENT;
|
70 |
IBLibrary := DoLoadLibrary(dllPathName)
|
71 |
end
|
72 |
end;
|
73 |
|
74 |
if IBLibrary = NilHandle then
|
75 |
{Use Registry key if it exists to locate library}
|
76 |
begin
|
77 |
with TRegistry.Create do
|
78 |
try
|
79 |
RootKey := HKEY_LOCAL_MACHINE;
|
80 |
if OpenKey('SOFTWARE\Firebird Project\Firebird Server\Instances',false) then
|
81 |
begin
|
82 |
if ValueExists('DefaultInstance') then
|
83 |
begin
|
84 |
InstallDir := ReadString('DefaultInstance') + 'bin' + DirectorySeparator ;
|
85 |
dllPathName := InstallDir + FIREBIRD_CLIENT;
|
86 |
IBLibrary := DoLoadLibrary(dllPathName)
|
87 |
end
|
88 |
end
|
89 |
finally
|
90 |
Free
|
91 |
end;
|
92 |
|
93 |
{Now try default install dir}
|
94 |
if IBLibrary = NilHandle then
|
95 |
begin
|
96 |
InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) +
|
97 |
DirectorySeparator + 'Firebird' +
|
98 |
DirectorySeparator + 'Firebird_3_0' +
|
99 |
DirectorySeparator + 'bin' + DirectorySeparator;
|
100 |
dllPathName := InstallDir + FIREBIRD_CLIENT;
|
101 |
IBLibrary := DoLoadLibrary(dllPathName)
|
102 |
end;
|
103 |
|
104 |
if IBLibrary = NilHandle then
|
105 |
begin
|
106 |
InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) +
|
107 |
DirectorySeparator + 'Firebird' +
|
108 |
DirectorySeparator + 'Firebird_2_5' +
|
109 |
DirectorySeparator + 'bin' + DirectorySeparator;
|
110 |
dllPathName := InstallDir + FIREBIRD_CLIENT;
|
111 |
IBLibrary := DoLoadLibrary(dllPathName)
|
112 |
end;
|
113 |
|
114 |
if IBLibrary = NilHandle then
|
115 |
begin
|
116 |
InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) +
|
117 |
DirectorySeparator + 'Firebird' +
|
118 |
DirectorySeparator + 'Firebird_2_1' +
|
119 |
DirectorySeparator + 'bin' + DirectorySeparator;
|
120 |
dllPathName := InstallDir + FIREBIRD_CLIENT;
|
121 |
IBLibrary := DoLoadLibrary(dllPathName)
|
122 |
end;
|
123 |
|
124 |
//Otherwise see if Firebird client is in path
|
125 |
//and rely on registry for location of firebird.conf and firebird.msg
|
126 |
if IBLibrary = NilHandle then
|
127 |
begin
|
128 |
IBLibrary := DoLoadLibrary(FIREBIRD_CLIENT);
|
129 |
if IBLibrary <= HINSTANCE_ERROR then
|
130 |
//well maybe InterBase is present...
|
131 |
IBLibrary := DoLoadLibrary(IBASE_DLL);
|
132 |
end;
|
133 |
end;
|
134 |
FOwnsIBLibrary := IBLibrary <> NilHandle;
|
135 |
end;
|
136 |
|
137 |
|