ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/client/include/wloadlibrary.inc
(Generate patch)

Comparing ibx/trunk/fbintf/client/include/wloadlibrary.inc (file contents):
Revision 55 by tony, Mon Jan 9 15:31:51 2017 UTC vs.
Revision 56 by tony, Mon Mar 6 10:20:02 2017 UTC

# Line 1 | Line 1
1   procedure TFBClientAPI.LoadIBLibrary;
2  
3 +  function IsValidHandle(aHandle: TLibHandle): boolean;
4 +  begin
5 +    Result := aHandle > HINSTANCE_ERROR;
6 +  end;
7 +
8    function DoLoadLibrary(LibName: string): TLibHandle;
9    begin
10      Result := LoadLibrary(PChar(LibName));
11 <    if Result <> NilHandle then
11 >    if IsValidHandle(Result) then
12      begin
13        FFBLibraryName := ExtractFileName(LibName);
14        FFBLibraryPath := ExtractFileDir(LibName);
15      end;
16    end;
17  
18 +  function GetSpecialFolder(const CSIDL: integer) : string;
19 +  {$IFDEF FPC}
20 +  begin
21 +    Result := GetWindowsSpecialDir(CSIDL);
22 +  end;
23 +  {$ELSE}
24 +  var
25 +    RecPath : PChar;
26 +  begin
27 +    RecPath := StrAlloc(MAX_PATH);
28 +    try
29 +    FillChar(RecPath^, MAX_PATH, 0);
30 +    if SHGetSpecialFolderPath(0, RecPath, CSIDL, false)
31 +      then result := RecPath
32 +      else result := '';
33 +    finally
34 +      StrDispose(RecPath);
35 +    end;
36 +  end;
37 +  {$ENDIF}
38 +
39   var InstallDir: string;
40      dllPathName: string;
41      oldFirebirdEV: string;
42   begin
43 <  if IBLibrary <> NilHandle then Exit;
43 >  if IsValidHandle(IBLibrary) then Exit;
44  
45    {First try any user override}
46    dllPathName := GetOverrideLibName;
47    if dllPathName <> '' then
48    begin
49      IBLibrary := DoLoadLibrary(dllPathName);
50 <    FOwnsIBLibrary := IBLibrary <> NilHandle;
50 >    FOwnsIBLibrary := IsValidHandle(IBLibrary);
51      Exit;
52    end;
53  
# Line 45 | Line 71 | begin
71      try
72        IBLibrary := DoLoadLibrary(dllPathName)
73      finally
74 <      if IBLibrary = NILHandle then
74 >      if not IsValidHandle(IBLibrary) then
75          SetEnvironmentVariable('FIREBIRD',PChar(oldFirebirdEV)); {restore}
76      end;
77    end;
78  
79   //  writeln('Dir = ',InstallDir);
80    {If FIREBIRD environment variable available then try this}
81 <  if IBLibrary = NilHandle then
81 >  if not IsValidHandle(IBLibrary) then
82    begin
83      InstallDir := GetEnvironmentVariable('FIREBIRD');
84      if (length(InstallDir) > 0) and (InstallDir[length(InstallDir)] <> DirectorySeparator) then
85 <      InstallDir += DirectorySeparator;
85 >      InstallDir := InstallDir + DirectorySeparator;
86      if (InstallDir <> '') and FileExists(InstallDir + FIREBIRD_CLIENT) then
87      begin
88        //assume firebird.conf and firebird.msg in same dir
# Line 71 | Line 97 | begin
97      end
98    end;
99  
100 <  if IBLibrary = NilHandle then
100 >  if not IsValidHandle(IBLibrary) then
101    {Use Registry key if it exists to locate library}
102    begin
103      with TRegistry.Create do
# Line 91 | Line 117 | begin
117      end;
118  
119      {Now try default install dir}
120 <    if IBLibrary = NilHandle then
120 >    if not IsValidHandle(IBLibrary) then
121      begin
122 <      InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) +
122 >      InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) +
123          DirectorySeparator + 'Firebird' +
124          DirectorySeparator + 'Firebird_3_0' +
125          DirectorySeparator + 'bin' + DirectorySeparator;
# Line 101 | Line 127 | begin
127        IBLibrary := DoLoadLibrary(dllPathName)
128      end;
129  
130 <    if IBLibrary = NilHandle then
130 >    if not IsValidHandle(IBLibrary) then
131      begin
132 <      InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) +
132 >      InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) +
133          DirectorySeparator + 'Firebird' +
134          DirectorySeparator + 'Firebird_2_5' +
135          DirectorySeparator + 'bin' + DirectorySeparator;
# Line 111 | Line 137 | begin
137        IBLibrary := DoLoadLibrary(dllPathName)
138      end;
139  
140 <    if IBLibrary = NilHandle then
140 >    if not IsValidHandle(IBLibrary) then
141      begin
142 <      InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) +
142 >      InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) +
143          DirectorySeparator + 'Firebird' +
144          DirectorySeparator + 'Firebird_2_1' +
145          DirectorySeparator + 'bin' + DirectorySeparator;
# Line 123 | Line 149 | begin
149  
150      //Otherwise see if Firebird client is in path
151      //and rely on registry for location of firebird.conf and firebird.msg
152 <    if IBLibrary = NilHandle then
152 >    if not IsValidHandle(IBLibrary) then
153      begin
154        IBLibrary := DoLoadLibrary(FIREBIRD_CLIENT);
155        if IBLibrary <= HINSTANCE_ERROR then
# Line 131 | Line 157 | begin
157         IBLibrary := DoLoadLibrary(IBASE_DLL);
158      end;
159    end;
160 <  FOwnsIBLibrary := IBLibrary <> NilHandle;
160 >  FOwnsIBLibrary := IsValidHandle(IBLibrary);
161   end;
162  
163  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines