Topic: мультиязычность в выподающем меню
вот скрипт меню
procedure SwitchMenu (Sender: string);
var
fiLang,reporfile:TStringList;
i,s,t,c: integer;
subfiLangi,mnFilereport,subfiLangiEdit,subfiLangirepor,subfiLangiDel,subfiLangiPrint,subfiLangipdf,mnFile,mnfiLangi,subFileNextUser,subFileClose,mnDictionary,subDictionaryPriceList,subDictionaryDash1,subDictionaryDash2,subDictionaryDash3,subDictionaryDash4,subDictionaryDash5,subDictionaryStatusEquipment,subDictionaryCompany,subDictionaryEquipment,subDictionaryBrand,subDictionaryAccessories,subFilereport,mnActivities,subEvents,subDonations : TMenuItem;
rta:TMainMenu;
mur:TForm;
begin
// если открыта форма * то переменная содежит имя этой формы
if sender = 'frmAdmin' then mur:=frmAdmin else
if sender = 'frmMasterWork' then mur:=frmMasterWork else
if sender = 'frmServiceCen' then mur:=frmServiceCen;
c := frmLogin.TMainMenu.Items.Count-1;
for i := c downto 0 do
if frmLogin.TMainMenu.Items[i].Visible then frmLogin.TMainMenu.Items[i].Free;
// создаем выподающее меню
mnFile := TMenuItem.Create (mur);
mnFile.Caption := pupmFa;
subFileNextUser := TMenuItem.Create (mur);
subFileNextUser.Caption := pupmnuser;
subFileNextUser.OnClick := @MenuClick1;
subFileClose := TMenuItem.Create (mur);
subFileClose.Caption := pupmex;
subFileClose.OnClick := @MenuClick2;
mnDictionary := TMenuItem.Create (mur);
mnDictionary.Caption := pupmlib;
subDictionaryPriceList := TMenuItem.Create (mur);
subDictionaryPriceList.Caption := pupmpr;
subDictionaryPriceList.OnClick := @MenuClick3;
subDictionaryDash1:= TMenuItem.Create (mur);
subDictionaryDash1.Caption := '-';
subDictionaryDash1.Enabled:= False;
subDictionaryStatusEquipment := TMenuItem.Create (mur);
subDictionaryStatusEquipment.Caption := pupmst;
subDictionaryStatusEquipment.OnClick := @MenuClick5;
subDictionaryDash2:= TMenuItem.Create (mur);
subDictionaryDash2.Caption := '-';
subDictionaryDash2.Enabled:= False;
subDictionaryCompany := TMenuItem.Create (mur);
subDictionaryCompany.Caption := pupmco;
subDictionaryCompany.OnClick := @MenuClick6;
subDictionaryEquipment := TMenuItem.Create (mur);
subDictionaryEquipment.Caption := pupmeq;
subDictionaryEquipment.OnClick := @MenuClick7;
subDictionaryBrand := TMenuItem.Create (mur);
subDictionaryBrand.Caption := pupmbr;
subDictionaryBrand.OnClick := @MenuClick8;
subDictionaryDash3:= TMenuItem.Create (mur);
subDictionaryDash3.Caption := '-';
subDictionaryDash3.Enabled:= False;
subDictionaryAccessories := TMenuItem.Create (mur);
subDictionaryAccessories.Caption := pupmeex;
subDictionaryAccessories.OnClick := @MenuClick9;
mnActivities := TMenuItem.Create (mur);
mnActivities.Caption := pupmhe;
subEvents := TMenuItem.Create (mur);
subEvents.Caption := pupmsi;
subEvents.OnClick := @MenuClick10;
subDictionaryDash4:= TMenuItem.Create (mur);
subDictionaryDash4.Caption := '-';
subDictionaryDash4.Enabled:= False;
subDonations := TMenuItem.Create (mur);
subDonations.Caption := pupmab;
subDonations.OnClick := @MenuClick11;
mnFilereport := TMenuItem.Create (mur);
mnFilereport.Caption := pupmreport;
subFilereport:= TMenuItem.Create (mur);
subFilereport.Caption := pupmreportnew;
subFilereport.OnClick := @clicknew;
subDictionaryDash5:= TMenuItem.Create (mur);
subDictionaryDash5.Caption := '-';
mnfiLangi := TMenuItem.Create (mur);
mnfiLangi.Caption := pupmlang;
// выводим выподающее меню
rta:=TMainMenu.Create(mur);
rta.Items.Add(mnFile);
mnFile.Add(subFileNextUser);
mnFile.Add(subFileClose);
rta.Items.Add(mnDictionary);
mnDictionary.Add(subDictionaryPriceList);
mnDictionary.Add(subDictionaryDash1);
mnDictionary.Add(subDictionaryStatusEquipment);
mnDictionary.Add(subDictionaryDash2);
mnDictionary.Add(subDictionaryCompany);
mnDictionary.Add(subDictionaryEquipment);
mnDictionary.Add(subDictionaryBrand);
mnDictionary.Add(subDictionaryDash3);
mnDictionary.Add(subDictionaryAccessories);
// выводим в выподающем меню список файлов мультиязычности
rta.Items.Add(mnfiLangi);
try
fiLang := TStringList.Create;
fiLang.Text := GetFilesList('languages','*.ini',False);
s := fiLang.Count-1;
for i:=0 to s do
begin
subfiLangi:= TMenuItem.Create (mur);
subfiLangi.Caption := ExtractFileName(fiLang[i]);
Delete(subfiLangi.Caption, Length(subfiLangi.Caption) -3 , 4);
subfiLangi.Hint := (fiLang[i]);
mnfiLangi.Add(subfiLangi);
subfiLangi.OnClick := @clicklang;
end;
finally
fiLang.free ;
end;
// выводим в выподющем меню список фалов отчетов
rta.Items.Add(mnFilereport);
mnFilereport.Add(subFilereport);
mnFilereport.Add(subDictionaryDash5);
reporfile := TStringList.Create;
reporfile.Text := GetFilesList( 'Report\','*.fr3',True); //ExtractFilePath(Application.ExeName) +
t := reporfile.Count-1;
for i:=0 to t do
begin
subfiLangirepor:= TMenuItem.Create (mur);
subfiLangirepor.Caption := ExtractFileName(reporfile[i]);
subfiLangirepor.Hint := (reporfile[i]);
mnFilereport.Add(subfiLangirepor);
Delete(subfiLangirepor.Caption, Length(subfiLangirepor.Caption) -3 , 4);
subfiLangiEdit := TMenuItem.Create(mur);
subfiLangiEdit.Caption := pupmreportedit;
subfiLangiEdit.Hint := (reporfile[i]);
subfiLangiDel := TMenuItem.Create(mur);
subfiLangiDel.Caption := pupmreportdel;
subfiLangiDel.Hint := (reporfile[i]);
subfiLangipdf := TMenuItem.Create(mur);
subfiLangipdf.Caption := 'PDF';
//subfiLangipdf.Hint := (fiLang[i]);
subfiLangiPrint := TMenuItem.Create(mur);
subfiLangiPrint.Caption := pupmreportprint;
subfiLangiPrint.Hint := (reporfile[i]);
subfiLangiEdit.OnClick := @clickEdit;
subfiLangiDel.OnClick := @clickDel;
subfiLangiPrint.OnClick := @clickPrint;
subfiLangipdf.OnClick := @clickpdf;
subfiLangirepor.Add(subfiLangiEdit);
subfiLangirepor.Add(subfiLangiDel);
subfiLangirepor.Add(subfiLangipdf);
subfiLangirepor.Add(subfiLangiPrint);
end;
rta.Items.Add(mnActivities);
mnActivities.Add(subEvents);
mnActivities.Add(subDictionaryDash4);
mnActivities.Add(subDonations);
end;
проблема в том, что вот эта часть
c := frmLogin.TMainMenu.Items.Count-1;
for i := c downto 0 do
if frmLogin.TMainMenu.Items[i].Visible then frmLogin.TMainMenu.Items[i].Free;
работает только на главной форме, если просто сменить имя формы получаю ошибку, как мне ее правельно записать?