Dzięki problem rozwiązany. Polegał on na tym że okna dialogowe mają dwa filtry i wprowadzało to błąd.
Moje drugie pytanie nadal zostało bez odpowiedzi...
Więc mam taki sobie unit LANG.PAS:
unit Lang;
interface
uses Forms, SysUtils, Classes, Menus, TypInfo, IniFiles,Dialogs;
type TJezyki = class
private
fForm : TForm;
fName : String;
fPath : String;
fLines: TStringList;
procedure GenerujPlik(Ini : TIniFile);
public
constructor Create(Form : TForm; Path : String;Name : String='');
destructor Destroy; override;
procedure WczytajJezyk;
procedure GenerujJezyk;
procedure Menu(M : TMenuItem);
procedure ZmianaClick(Sender : TObject);
procedure WczytajPlikJezyka(Ini : TIniFile);
procedure Dodaj(Nr : Integer;S : String);
function Pobierz(Nr : Integer; S : String = '') : String;
property Name : String read fName;
end;
implementation
uses Unit1, Unit2;
procedure TJezyki.Dodaj(Nr : Integer;S : String);
begin
while (Nr>=fLines.Count) do fLines.Add('');
fLines[Nr]:=S;
end;
function TJezyki.Pobierz(Nr : Integer; S : String = '') : String;
begin
if (Nr<0) or (Nr>fLines.Count-1) then Result:=S else Result:=fLines[Nr];
end;
//-----------------------------------------------------------
constructor TJezyki.Create(Form : TForm; Path: String; Name : String='');
begin
inherited Create;
if Form=nil then Exit;
fForm:=Form;
fPath:=Path;
fLines:=TStringList.Create;
if Name='' then fName:=fForm.Name else fName:=Name;
end;
destructor TJezyki.Destroy;
begin
fLines.Free;
end;
//-----------------------------------------------------------
procedure TJezyki.GenerujJezyk;
var i : Integer;
Ini : TIniFile;
begin
if (fName='') then exit;
Ini:=TIniFile.Create(fPath+fName+'.lng');
GenerujPlik(Ini);
for i:=0 to fLines.Count-1 do Ini.WriteString(fName,'_T'+IntToStr(i),fLines[i]);
Ini.Free;
end;
//********************************************************************
//najwazniejsza funkcja przeszukujaca fForm!
//*******************************************************************
procedure TJezyki.GenerujPlik(Ini : TIniFile);
var i : Integer;
C : TComponent;
N,WC,WH,WT,WF : String;
begin
Ini.WriteString(fName,'C:',fForm.Caption);
For i:=0 to fForm.ComponentCount-1 do
begin
C:=fForm.Components[i];
N:=C.Name;
WC:='';
WH:='';
WT:='';
if Copy(N,1,6)='MN_DYN' then Continue;
if IsPublishedProp(C,'Caption') then WC:=GetPropValue(C,'Caption');
if IsPublishedProp(C,'Text') then WT:=GetPropValue(C,'Text');
if IsPublishedProp(C,'Hint') then WH:=GetPropValue(C,'Hint');
// if IsPublishedProp(C,'Filter') then WF:=GetPropValue(C,'Filter');
if WC<>'' then Ini.WriteString(fName,'C:'+N,WC);
if WH<>'' then Ini.WriteString(fName,'H:'+N,WH);
if WT<>'' then Ini.WriteString(fName,'T:'+N,WT);
// if WF<>'' then Ini.WriteString(fName,'F:'+N,WF);
end;
end;
//------------------------------------------------------------------------------
procedure TJezyki.WczytajPlikJezyka(Ini : TIniFile);
var i : Integer;
K : TComponent;
A,B,C : String;
TP : TStringList;
begin
fForm.Caption:=Ini.ReadString(fName,'C:',fForm.Caption);
TP:=TStringList.Create;
Ini.ReadSection(fName,TP);
for i:=0 to TP.Count-1 do
begin
A:=TP[i]; //cala linijka
B:=Ini.ReadString(fName,A,''); //sama wartosc
C:=A[1]; //typ
Delete(A,1,2); //usuwamy z A typ - mamy nazwe
if (B='') or (A='') then Continue;
K:=fForm.FindComponent(A);
if Assigned(K) then
begin
if (C='C') and IsPublishedProp(K,'Caption') then SetPropValue(K,'Caption',B);
if (C='T') and IsPublishedProp(K,'Text') then SetPropValue(K,'Text',B);
if (C='H') and IsPublishedProp(K,'Hint') then SetPropValue(K,'Hint',B);
if (C='F') and IsPublishedProp(K,'Filter') then SetPropValue(K,'Filter',B);
end;
end;
TP.Free;
end;
procedure TJezyki.WczytajJezyk;
var Ini : TIniFile;
i : Integer;
begin
if FileExists(fPath+fName+'.lng') then
begin
Ini:=TIniFile.Create(fPath+fName+'.lng');
WczytajPlikJezyka(Ini);
for i:=0 to fLines.Count-1 do fLines[i]:=Ini.ReadString(fName,'_T'+IntToStr(i),fLines[i]);
Ini.Free;
end;
end;
//------------------------------------------------------------------------------
procedure TJezyki.Menu(M : TMenuItem);
var n : TMenuItem;
i : Integer;
SearchRec : TSearchRec;
begin
i:=1;
FindFirst(fPath+'*.lng',faAnyFile, SearchRec);
repeat
n := TMenuItem.Create(fForm);
n.Hint:=Copy(SearchRec.Name,1,Length(SearchRec.Name)-4);
n.Caption:=n.Hint;
if n.Hint=fName then n.Checked:=TRUE;
n.Name:='MN_DYN_Jezyk_'+IntToStr(i);
n.OnClick:=ZmianaClick;
M.Add(n);
Inc(i);
until FindNext(SearchRec)<>0;
FindClose(SearchRec);
end;
procedure TJezyki.ZmianaClick(Sender : TObject);
var K : TComponent;
i : Integer;
begin
if fForm=nil then exit;
fName:=TMenuItem(Sender).Hint;
for i:=1 to 20 do
begin
K:=fForm.FindComponent('MN_DYN_Jezyk_'+IntToStr(i));
if Assigned(K) and (K is TMenuItem) then TMenuItem(K).Checked:=FALSE;
end;
WczytajJezyk;
TMenuItem(Sender).Checked:=TRUE;
end;
end.
Jak można to przerobić by przeszukiwane były wszystkie formy aplikacji lub po prostu podane formy aplikacji.