unit Language;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
procedure ReadLangIni(aForm: TForm; aType: TClass;
const aProperty:
string = '
Text');
overload;
procedure ReadLangIni(aForm: TForm; aType, ASubType: TClass;
const aProperty:
string = '
Text');
overload;
procedure WriteLangIni(aForm: TForm; aType: TClass;
const aProperty:
string = '
Text');
overload;
procedure WriteLangIni(aForm: TForm; aType, ASubType: TClass;
const aProperty:
string = '
Text');
overload;
resourcestring
SUnknownProperty = '
Eigenschaft %s existiert nicht.';
implementation
uses
TypInfo, IniFiles, frmSetup;
function MyGetWideStrProp(Instance: TObject;
const PropName:
string): Widestring;
var
PropInfo: PPropInfo;
begin
PropInfo := GetPropInfo(Instance, PropName);
if PropInfo =
NIL then
begin
raise EPropertyError.CreateResFmt(@SUnknownProperty, [PropName]);
end;
result := GetWideStrProp(Instance, PropName);
end;
procedure MySetWideStrProp(Instance: TObject;
const PropName:
string;
const Value: Widestring);
var
PropInfo: PPropInfo;
begin
PropInfo := GetPropInfo(Instance, PropName);
if PropInfo =
NIL then
begin
raise EPropertyError.CreateResFmt(@SUnknownProperty, [PropName]);
end;
SetWideStrProp(Instance, PropInfo, Value);
end;
procedure WriteLangIni(aForm: TForm; aType: TClass;
const aProperty:
string = '
Text');
var
CurrentCompo: TComponent;
ndx: Integer;
TranslateIni: TMemIniFile;
CurrentText:
string;
begin
TranslateIni := TMemIniFile.Create(Programmpfad + '
\default.lng');
try
for ndx := 0
to Pred(aForm.ComponentCount)
do
begin
CurrentCompo := aForm.Components[ndx];
if (CurrentCompo
is aType)
then
begin
CurrentText := MyGetWideStrProp(CurrentCompo, aProperty);
TranslateIni.WriteString(CurrentCompo.ClassName + '
-' + aProperty,
CurrentCompo.
Name, CurrentText);
end;
end;
TranslateIni.UpdateFile;
finally
TranslateIni.Free;
end;
end;
// Das ist die überladene Funktion mit der Unterkompo
procedure WriteLangIni(aForm: TForm; aType, aSubType: TClass;
const aProperty:
string = '
Text');
var
CurrentCompo: TComponent;
SubCompo: TComponent;
ndx: Integer;
subndx: Integer;
TranslateIni: TMemIniFile;
CurrentText:
string;
begin
TranslateIni := TMemIniFile.Create(ProgrammPfad + '
\default.lng');
try
for ndx := 0
to Pred(aForm.ComponentCount)
do
begin
CurrentCompo := aForm.Components[ndx];
if (CurrentCompo
is aType)
then
begin
for subndx := 0
to Pred(currentcompo.ComponentCount)
do // Hier suche ich die Unterkomponente
begin
SubCompo := CurrentCompo.Components[subndx];
if (SubCompo
is aSubType)
then
begin
CurrentText := MyGetWideStrProp(SubCompo, aProperty);
TranslateIni.WriteString(CurrentCompo.ClassName + '
-' + SubCompo.ClassName + '
-' + aProperty,
CurrentCompo.
Name, CurrentText);
end;
end;
end;
end;
TranslateIni.UpdateFile;
finally
TranslateIni.Free;
end;
end;
procedure ReadLangIni(aForm: TForm; aType: TClass;
const aProperty:
string = '
Text');
var
CurrentCompo: TComponent;
ndx: Integer;
TranslateIni: TMemIniFile;
NewText:
string;
begin
TranslateIni := TMemIniFile.Create(ProgrammPfad + '
\default.lng');
try
for ndx := 0
to Pred(aForm.ComponentCount)
do
begin
CurrentCompo := aForm.Components[ndx];
if (CurrentCompo
is aType)
then
begin
NewText := TranslateIni.ReadString(CurrentCompo.ClassName + '
-' +
aProperty, CurrentCompo.
Name, '
');
MySetWideStrProp(CurrentCompo, aProperty, NewText);
end;
end;
finally
TranslateIni.Free;
end;
end;
// Das ist die überladene Funktion mit der Unterkompo
procedure ReadLangIni(aForm: TForm; aType, ASubType: TClass;
const aProperty:
string = '
Text');
var
CurrentCompo: TComponent;
SubCompo: TComponent;
ndx: Integer;
subndx: Integer;
TranslateIni: TMemIniFile;
NewText:
string;
begin
TranslateIni := TMemIniFile.Create(ProgrammPfad + '
\default.lng');
try
for ndx := 0
to Pred(aForm.ComponentCount)
do
begin
CurrentCompo := aForm.Components[ndx];
if (CurrentCompo
is aType)
then
begin
for subndx := 0
to Pred(currentcompo.ComponentCount)
do // Hier suche ich die Unterkomponente
begin
SubCompo := CurrentCompo.Components[subndx];
if (SubCompo
is aSubType)
then
begin
NewText := TranslateIni.ReadString(CurrentCompo.ClassName + '
-' + SubCompo.ClassName + '
-' + aProperty, CurrentCompo.
Name, '
');
MySetWideStrProp(SubCompo, aProperty, NewText);
end;
end;
end;
end;
TranslateIni.UpdateFile;
finally
TranslateIni.Free;
end;
end;
end.