Page 1 of 1

Language dispatcher=nil in FormCreate

Posted: Thu Jul 06, 2017 2:20 am
by rodney232
I have a large Delphi project that supports 6 languages (English is default).
When the app is running, I can change to each language by setting the siLangDispatcher.ActiveLanguage appropriately.
I have the following code to set the appropriate active language in the main form's FormCreate method;

Code: Select all

procedure TMainForm.FormCreate(Sender: TObject);
var
  vLanguageID: DWORD;

begin
  // set language (using only primary language identifier -> last byte)
  vLanguageID := GetUserDefaultLangID;
  case Byte(vLanguageID and $00FF) of
    LANG_ENGLISH:  siLangDispatcher.ActiveLanguage := 1;
    LANG_ARABIC:   siLangDispatcher.ActiveLanguage := 2;
    LANG_CHINESE:  siLangDispatcher.ActiveLanguage := 3;
    LANG_JAPANESE: siLangDispatcher.ActiveLanguage := 4;
    LANG_SPANISH:  siLangDispatcher.ActiveLanguage := 5;
    LANG_GERMAN:   siLangDispatcher.ActiveLanguage := 6;
    else
      siLangDispatcher.ActiveLanguage := 1;
    end;

  UpdateStrings;
  etc;
If I change regions (in Win10) to either English(Australia), Arabic(Saudi Arabia), Chinese(Simplified China) or German(Austria), the siLangDispatcher is not nil and the app starts up correctly showing the appropriate language.
If the region is set to either Japanese(Japan) or Spanish(Spain) then the siLangDispatcher is nil upon entry to the FormCreate and the app fails.
Any idea why this is happening?
I'm using Delphi Berlin Update 2 and Si components 7.5.6.1.

Posted: Sat Jul 08, 2017 6:59 pm
by isiticov
Hello,

Creation/initialization of dispatcher isn't related to application's running region. So I would suppose that there might be some code in your application that either prevents dispatcher from creation or destroys it somehow. If you can reproduce this problem on some simple sample project then please send it to us to test.
Thank you.

Posted: Mon Jul 10, 2017 3:07 pm
by Malcolm
What value does GetUserDefaultLangID return for the failing Languages (before ANDing it)?

Are you able or willing to use System.SysUtils.TSysLocale ?

This works for me:

Code: Select all

VAR
  ALanguage: Integer;
BEGIN
  // we only come here if the Active Language has not been set by user.
   ALanguage := SysLocale.PriLangID;
  CASE ALanguage OF
    LANG_CATALAN: Language := 15; 
    LANG_CHINESE: Language := 13; 
    LANG_DANISH:   Language := 9; 
    LANG_GERMAN:  Language := 4; 
    LANG_SPANISH: Language := 5; 
    ....
  else
    Language := 1;

Posted: Wed Jul 12, 2017 6:29 am
by rodney232
Thanks guys for the replies.
It turns out that I had inadvertently left some legacy language support code in an initialization section of one of my units. This code loaded the current language resource file which understandably clashed with the siLang components. All is good now!