home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue66 / Construc / Refactor / Source / IDELibPath.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-10-09  |  3.1 KB  |  127 lines

  1. unit IDELibPath;
  2. // from GX_experts Backup.pas
  3. interface
  4. uses classes;
  5.  
  6. Function GetIdeLibraryPath(version : string = '5') : tstringlist;
  7.  
  8. implementation
  9. Uses sysutils, FileCtrl, registry, Windows, controls, dialogs, fExtractLibPath;
  10.   //, ToolIntf, ExptIntf,  ToolsApi;
  11.  
  12. Function GetIdeLibraryPath(version : string = '5') : tstringlist;
  13. const
  14.   LibrarySection = '\Library';
  15. {$IFDEF VER100}
  16.   LibraryPathValue = 'SearchPath';
  17. {$ELSE}
  18.   LibraryPathValue = 'Search Path';
  19. {$ENDIF VER100}
  20.  
  21.   IdeBase = '$(DELPHI)';
  22.  
  23.  
  24. var
  25.   BasePath: string;
  26.  
  27.   procedure AddPathItemToList(PathItem: string);
  28.   var
  29.     IdeBasePos: Integer;
  30.   begin
  31.     PathItem := UpperCase(PathItem);
  32.  
  33.     // Expand the folder name if necessary $(DELPHI); $(BCB), VER110 and up
  34.       IdeBasePos := Pos(IdeBase, PathItem);
  35.       if IdeBasePos > 0 then
  36.       begin
  37.         Delete(PathItem, IdeBasePos, Length(IdeBase));
  38.         Insert(BasePath, PathItem, IdeBasePos);
  39.       end;
  40.     // Make sure that every item has a trailing slash.
  41.     // This simplifies processing when we scan for files.
  42.     // not needed as we just want a list to pass to the compiler via -U
  43. //    PathItem := AddSlash(PathItem);
  44.  
  45.     // verify that the directory exists
  46.     if DirectoryExists(PathItem) then
  47.     begin
  48. //      Result.add(ExtractShortPathName(PathItem));
  49.       Result.add(PathItem);
  50.       {if pos(' ', pathitem) > 0
  51.         then Result.Add('"'+PathItem+'"')
  52.         else Result.add(PathItem);
  53.       }
  54.     end;
  55.   end;
  56.  
  57. var
  58.   PathString: string;
  59.   PathItem: string;
  60.   CPos: Integer;
  61.   pathname : string;
  62. begin
  63.   with tf_ExtractLibPath.create(nil) do begin
  64.     edit1.text := version;
  65.     if ShowModal = mrOK
  66.       then begin
  67.          version := edit1.text;
  68.          if not ((version = '5') or (version = '4'))
  69.            then begin
  70.               ShowMessage('Only 4 and 5 supported at this time for automated library path extraction');
  71.               free;
  72.               exit;
  73.               end;
  74.          end
  75.       else begin
  76.         free;
  77.         exit;
  78.         end;
  79.     free;
  80.     end;
  81.  
  82.   result := tstringlist.create;
  83.   {$Ifdef VER130}
  84.     pathname := '\Software\Borland\Delphi\'+version+'.0';
  85.   {$ENDIF}
  86.   {$Ifdef VER120}
  87.     pathname := '\Software\Borland\Delphi\'+version+'.0';
  88.   {$ENDIF}
  89.  
  90.   with TRegistry.Create do
  91.   try
  92.       //if OpenKey(ToolServices.GetBaseRegistryKey + LibrarySection, False)
  93.     if OpenKey(pathname + LibrarySection, False)
  94.       then begin
  95.         PathString := ReadString(LibraryPathValue);
  96.         CloseKey;
  97.         end;
  98.  
  99.     RootKey := HKEY_LOCAL_MACHINE;
  100.      // if OpenKey(ToolServices.GetBaseRegistryKey, False)
  101.     if OpenKey(pathname, False)
  102.       then begin
  103.         BasePath := ReadString('RootDir');
  104.         CloseKey;
  105.         end;
  106.   finally
  107.     Free;
  108.   end;
  109.  
  110.   CPos := Pos(';', PathString);
  111.   while CPos > 0 do
  112.   begin
  113.     PathItem := Trim(Copy(PathString, 1, CPos-1));
  114.     if PathItem <> '' then
  115.       AddPathItemToList(PathItem);
  116.  
  117.     Delete(PathString, 1, CPos);
  118.     CPos := Pos(';', PathString);
  119.   end;
  120.   PathString := Trim(PathString);
  121.   if PathString <> '' then
  122.     AddPathItemToList(PathItem);
  123. end;
  124.  
  125.  
  126. end.
  127.