Search code examples
delphidelphi-7

Delphi: DKLang: can someone fix issue with 2 forms of the same class


DKLang is Localization package. I have an old issue when 2 or more forms of the same class aren't translated (only 1st of them is translated, others are in English). I mean forms created dynamically.

Can someone fix this? Author of DKlang doesn't respond for year.

EDIT How to see in action: demo project (6KB RAR, source only) download here. After compiling, press main button- you'll see 3 instances of sample form, 1st is localized, others 2 are not. Requires non-Unicode Delphi + TNT Unicode Controls + DKLang 3.x

Demo project


Solution

  • Seems i found it. My fix is two new lines in TDKLang_CompTranslations.FindComponentName which are for names "Form2_1", "Form2_2"

    function TDKLang_CompTranslations.FindComponentName(sComponentName: String): TDKLang_CompTranslation;
      var idx: Integer;
      begin
        idx := Pos('_', sComponentName); //added
        if idx>0 then System.Delete(sComponentName, idx, MaxInt); //added
    
        idx := IndexOfComponentName(sComponentName);
        if idx<0 then Result := nil else Result := GetItems(idx);
      end;