ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/client/include/wloadlibrary.inc
Revision: 45
Committed: Tue Dec 6 10:33:46 2016 UTC (7 years, 11 months ago) by tony
File size: 4423 byte(s)
Log Message:
Committing updates for Release R2-0-0

File Contents

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