if FSIComponents.Count > 0 then
begin
FLangNames.Assign(TsiCustomLang(FSIComponents[0]).FLangNames);
FNumOfLanguages := TsiCustomLang(FSIComponents[0]).NumOfLanguages;
end;
if FSIComponents.Count > 0 then
begin
LangNames.Assign(TsiCustomLang(FSIComponents[0]).FLangNames);
NumOfLanguages := TsiCustomLang(FSIComponents[0]).NumOfLanguages;
end;
? Note the difference in using the setters for these properties. This is relevant if the external file contains a different number of languages compared to the design-type values.
OK, but I get an ELanguageError after running this code. It happens when the .sib file has more languages than are defined design-time. The LoadAllFromFile completes OK, but when I later set the LangDispatcher.ActiveLanguage property to the new value, I get the error message because one of the TsiLang components has a lower NumOfLanguages value.
I guess the problem is in very rare case (and it might be your case) when first TsiLang in disptacher's list has less languages defined in SIB file than others and as result dispatcher receives lower values. I suggest it is better to correct the SIB file.
I did check the .sib file with the SILEditor (that's how I added the new language to it), and as far as I can see all units and forms show that language column. How would I 'correct' the sib file in this case?
Also, please understand that this is not an exotic problem. We want to be able to have users add a new language by allowing them to edit the .sib file using the SILEditor. Those languages will not be pre-defined in the TsiLangDispatcher in the executable. So loading new languages from the .sib file should work seamlessly for us.
Actually, this is quite usual way allowing users to define their own languages. And we ourselves use same technique in our Resource Builder. Users able to add new languages there as well.
If SIB file lists all languages correctly, then the problem might be somewhere else. May be there is one form in your project, which is not included in the SIB file and it might cause such problem.
The code fragment I posted above solves the problem; does that give you any clue as to where the problem is?
As to a form missing from the sib file: I created it from the Language Expert doing a 'Save Project' from it - so I assume that includes all forms in the project.
if FSIComponents.Count > 0 then
begin
LangNames := TsiCustomLang(FSIComponents[0]).FLangNames;
NumOfLanguages := TsiCustomLang(FSIComponents[0]).NumOfLanguages;
end;
This code is a little bit overfull but in order just to be sure that all linked TsiLangs have all properties synchronized with dispatcher.