Language dispatcher=nil in FormCreate

This forum designated to discuss the TsiLang Components Suite.
Post Reply
Posts: 8
Joined: Mon Mar 27, 2017 10:04 pm

Language dispatcher=nil in FormCreate

Post 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);
  vLanguageID: DWORD;

  // 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;
      siLangDispatcher.ActiveLanguage := 1;

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

Site Admin
Posts: 2210
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »


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.
Best regards,
Igor Sitikov.

Posts: 106
Joined: Tue Jan 21, 2003 5:18 pm
Location: Scotland

Post 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

  ALanguage: Integer;
  // 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; 
    Language := 1;

Posts: 8
Joined: Mon Mar 27, 2017 10:04 pm

Post 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!

Post Reply