-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLanguageIni.pas
More file actions
110 lines (98 loc) · 3.23 KB
/
Copy pathLanguageIni.pas
File metadata and controls
110 lines (98 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
unit LanguageIni;
interface
uses
System.SysUtils, System.Classes, System.Generics.Collections, System.IniFiles,
Vcl.StdCtrls, vcl.ComCtrls, vcl.ExtCtrls, System.IOUtils, vcl.Dialogs;
type
TLangIni = class(TObject)
private
protected
public
class procedure buildIni(comp : TComponent; sect : String; lang : String);
class procedure ReadLanguage(comp : TComponent; sect : String; lang: string);
class procedure GetLanguages(list : Tstrings);
end;
implementation
class procedure TLangIni.buildIni(comp: TComponent; sect: string; lang: string);
var i:integer;
ini : TIniFile;
filename : string;
procedure handleComp(c: TComponent; sect : string);
var i:integer;
x : string;
begin
if not ini.ValueExists(sect,c.name) then
begin
x := '';
if (c is TTabSheet) then x := (c AS TTabSheet).Caption;
if (c is TLabel) then x := (c AS TLabel).Caption;
if (c is TButton) then x := (c AS TButton).Caption;
if (c is TPanel) then x := (c AS TPanel).Caption;
if (c is TCheckBox) then x := (c AS TCheckBox).Caption;
if (c is TRadioButton) then x := (c AS TRadioButton).Caption;
if (c is TOpenDialog) then x := (c AS TopenDialog).Title;
if (x <> '') then Ini.WriteString(sect, c.name, x);
end;
if c.ComponentCount > 0 then
for i := 0 to c.ComponentCount -1 do handleComp(c.Components[i],sect);
end;
begin
filename := tPath.GetPublicPath + '\GFX_Tool\lang'+lang+'.ini';
ini := TIniFile.Create(filename);
try
for i := 0 to comp.ComponentCount - 1 do handleComp(comp.Components[i],Sect);
finally
ini.Free;
end;
end;
class procedure TLangIni.ReadLanguage(comp : TComponent; sect : string; lang: string);
var ini : TiniFile;
l : TStringList;
filename : string;
i : integer;
c : Tcomponent;
begin
filename := tPath.GetPublicPath + '\GFX_Tool\lang'+lang+'.ini';
l:= TStringlist.Create;
try
ini := TIniFile.Create(filename);
try
ini.ReadSection(sect,l);
for i := 0 to l.Count - 1 do
begin
c := comp.FindComponent(l[i]);
if (c is TTabSheet) then (c AS TTabSheet).Caption := ini.ReadString(sect,l[i],'');
if (c is TLabel) then (c AS TLabel).Caption := ini.ReadString(sect,l[i],'');
if (c is TButton) then (c AS TButton).Caption := ini.ReadString(sect,l[i],'');
if (c is TPanel) then (c AS TPanel).Caption := ini.ReadString(sect,l[i],'');
if (c is TCheckBox) then (c AS TCheckBox).Caption := ini.ReadString(sect,l[i],'');
if (c is TRadioButton) then (c AS TRadioButton).Caption := ini.ReadString(sect,l[i],'');
if (c is TOpenDialog) then (c AS TopenDialog).Title := ini.ReadString(sect,l[i],'');
end;
finally
ini.Free;
end;
finally
l.Free;
end;
end;
class procedure TLangIni.GetLanguages(list : Tstrings);
var SR : TsearchRec;
dir: String;
nam : String;
begin
dir := tPath.GetPublicPath + '\GFX_Tool\';
if FindFirst(dir+'lang*.ini',faNormal,SR) = 0 then
begin
try
repeat
nam := TPath.GetFileNameWithoutExtension(SR.Name);
nam := nam.Substring(4);
list.add(nam);
until FindNext(SR)<>0;
finally
FindClose(SR); //Nach jedem findfirst nötig, um sr freizugeben!
end;
end;
end;
end.