start application with nls_lang environment variable

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sinys
Posts: 186
Joined: Tue 21 Feb 2012 03:44

start application with nls_lang environment variable

Post by sinys » Sat 02 Feb 2013 12:07

I want start application like this
C:\>set nls_lang=...
C:\>MyApp.exe

At now moment application start with NLS_LANG in registry, how I can check current NLS_LANG on registry tools from ODAC for given OracleHome?
I want compare NLS_LANG from environment variable and NLS_LANG from registry from selected OracleHome and if they different then send alter session command (after session connected).

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: start application with nls_lang environment variable

Post by AlexP » Mon 04 Feb 2013 13:15

Hello,

The information about Oracle clients is located in the HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ registry branch. To define the NLS_LANG variable value, you can use the TRegistry class, the current Home can be retrieved from the OracleHomes array using the OraSession1.Home property

Code: Select all

uses  ... , Registry, OraCall;
....
var
  pReg: TRegistry;
begin
  pReg := TRegistry.Create(KEY_READ);
  try
    pReg.RootKey := HKEY_LOCAL_MACHINE;
    if pReg.OpenKey('\SOFTWARE\Oracle\' + OracleHomes[Integer(OraSession1.Home) - 1].Key, False) then
      if pReg.ReadString('NLS_LANG') <> GetEnvironmentVariable('NLS_LANG') then
        ShowMessage('do something');
  finally
    pReg.Free;
  end;
end;

Post Reply