Title: Language Combobox
Question: This is an example how to select different languages/locales.
Answer:
// Free code from Lothar Rausch
// http://www.oeko.de
unit G4LocalesComboBox;
{$EXTENDEDSYNTAX ON}
interface
uses
StdCtrls, Windows;
type
TG4LocalesComboBox = class(TCustomComboBox)
private
function GetLangID : LCID;
procedure SetLangID (NewLCID : LCID);
protected
procedure Loaded; override;
public
property LangID : LCID read GetLangID write SetLangID;
published
property OnChange;
end;
procedure Register;
implementation
uses
Classes, SysUtils;
// private
function TG4LocalesComboBox.GetLangID : LCID;
begin
Result := Languages.LocaleID [LongInt (Items.Objects [ItemIndex])];
end;
procedure TG4LocalesComboBox.SetLangID (NewLCID : LCID);
var
i : integer;
begin
if NewLCID = 0
then NewLCID := GetUSerDefaultLangID;
i := Languages.IndexOf (NewLCID);
if i = 0
then ItemIndex := Items.IndexOfObject (TObject (i))
else ItemIndex := -1;
end;
// protected
procedure TG4LocalesComboBox.Loaded;
var
Lan : TLanguages;
i : integer;
begin
inherited Loaded;
Style := csDropDownList;
Sorted := true;
if not (csDesigning in ComponentState)
then begin
Lan := Languages;
for i := 0 to Lan.Count - 1 do
Items.AddObject (Lan.Name [i], TObject (i));
LangID := 0;
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [TG4LocalesComboBox]);
end;
end.