3

I want to get the library path for a specific platform (win32, win64, OSx). But, when I ask for the library path for, OTA just return me the OSx library path.

The code is:

EnvironmentOptions := (BorlandIDEServices as IOTAServices).GetEnvironmentOptions;
Paths.Text := EnvironmentOptions.Values['LibraryPath'];

I noticed a strange thing. When I ask for the key values I get 3 LibraryPath.

When I do:

EnvironmentOptions.GetOptionNames

I get:

... A lot of values 
'ClassCompletionBooleanAddInterface', tkEnumeration
'LibraryPath', tkLString                --> 1
'PackageDPLOutput', tkLString
...  lot of values 
'LibraryPath', tkLString                --> 2
'PackageDPLOutput', tkLString
...  lot of values 
'HPPOutputDirectory', tkLString
'LibraryPath', tkLString                --> 3
'PackageDPLOutput', tkLString
...  lot of values 

I THINK that each key must represent one of the possible targets that I have (win32, win64, OSx). But as I just can call the value of the Key for it's name, it always return me the first key that it founds, in my case it's OS X.

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
Rodrigo Farias Rezino
  • 2,687
  • 3
  • 33
  • 60

1 Answers1

4

I'll not accept my answer as correct, it's just an option. I didn't found a possibility to do it direct in OTA so I looked for it on the registry:

procedure GetLibraryPath(Paths: TStrings; PlatformName: string);
var
  Svcs: IOTAServices;
  Options: IOTAEnvironmentOptions;
  Text: string;
  List: TStrings;
  ValueCompiler: string;
  RegRead: TRegistry;
begin
  Svcs := BorlandIDEServices as IOTAServices;
  if not Assigned(Svcs) then Exit;
  Options := Svcs.GetEnvironmentOptions;
  if not Assigned(Options) then Exit;

  ValueCompiler := Svcs.GetBaseRegistryKey;

  RegRead := TRegistry.Create;
  List := TStringList.Create;
  try
    if PlatformName = '' then
      Text := Options.GetOptionValue('LibraryPath')
    else
    begin
      RegRead.RootKey := HKEY_CURRENT_USER;
      RegRead.OpenKey(ValueCompiler + '\Library\' + PlatformName, False);
      Text := RegRead.GetDataAsString('Search Path');
    end;

    List.Text := StringReplace(Text, ';', #13#10, [rfReplaceAll]);
    Paths.AddStrings(List);

    if PlatformName = '' then
      Text := Options.GetOptionValue('BrowsingPath')
    else
    begin
      RegRead.RootKey := HKEY_CURRENT_USER;
      RegRead.OpenKey(ValueCompiler + '\Library\' + PlatformName, False);
      Text := RegRead.GetDataAsString('Browsing Path');
    end;

    List.Text := StringReplace(Text, ';', #13#10, [rfReplaceAll]);
    Paths.AddStrings(List);
  finally
    RegRead.Free;
    List.Free;
  end;
end;
Rodrigo Farias Rezino
  • 2,687
  • 3
  • 33
  • 60
  • Does it work? Oh and thanks for the `GetBaseRegistryKey`. I didn't know this one, and it comes in handy in a piece of code I'm writing right now. Very handy. – Rudy Velthuis Aug 08 '16 at 17:19
  • Then you'll get an upvote for finding an answer yourself. Very good! It is probably the *only* way to get the values you want. Hmmm... it is not good that `IOTAEnvironmentOptions.Values[]` returns duplicate keys. They should be named differently for the different platforms, IMO. E.g. `'LibraryPathMacOS'`, etc. – Rudy Velthuis Aug 08 '16 at 17:23
  • 1
    FWIW, I reported it on Quality Portal: https://quality.embarcadero.com/browse/RSP-15614 . – Rudy Velthuis Aug 08 '16 at 18:01
  • 1
    I found 7 sets of duplicate keys in my 10.1 Berlin Architect. – Rudy Velthuis Aug 09 '16 at 00:07