
11.11.2010, 23:21
|
 |
Гуру
|
|
Регистрация: 09.03.2009
Адрес: На курорте, из окна вижу теплое Баренцево море. Бррр.
Сообщения: 4,723
Репутация: 52347
|
|
Не думаю, что cxPropertiesStore имеет смысл использовать для данной задачи. Насколько я понял, основное его применение сохранить/загрузить свойства для статических элементов - например форма настроек программы. Я так и использовал. А вот для динамического списка с произвольной вложенностью элементов похоже он уж не катит. Вот так можно все это дело замутить:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, IniFiles, ExtCtrls;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N31: TMenuItem;
N21: TMenuItem;
N11: TMenuItem;
N311: TMenuItem;
N321: TMenuItem;
N3111: TMenuItem;
PopupMenu2: TPopupMenu;
Panel1: TPanel;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TSectionIniFile = array of record Key,Value: String end;
THelperIniFile = class helper for TIniFile
function ReadSectionIdentsAndValues(const Section: string): TSectionIniFile;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function THelperIniFile.ReadSectionIdentsAndValues(const Section: string): TSectionIniFile;
Var
Strings: TStringList;
i: Integer;
begin
Strings := TStringList.Create;
ReadSectionValues(Section, Strings);
SetLength(Result,Strings.Count);
for i := 0 to Length(Result)-1
do begin
Result[i].Key := Copy(Strings[i],1,Pos('=',Strings[i])-1);
Result[i].Value := Copy(Strings[i],Pos('=',Strings[i])+1);
end;
end;
procedure SaveMenu(IniFile: TIniFile; Item: TMenuItem; Section: String);
Var i: Integer;
begin
for i := 0 to Item.Count - 1
do begin
if Item[i].Count > 0
then SaveMenu(IniFile, Item[i], Item[i].Caption);
IniFile.WriteString(Section,IntToStr(i),Item[i].Caption);
end;
end;
procedure LoadMenu(IniFile: TIniFile; Item: TMenuItem; Section: String);
Var i: Integer;
MenuItem: TMenuItem;
Items: TSectionIniFile;
begin
Items := IniFile.ReadSectionIdentsAndValues(Section);
for i := 0 to Length(Items)- 1
do begin
MenuItem := TMenuItem.Create(Item);
MenuItem.Caption := Items[i].Value;
Item.Add(MenuItem);
LoadMenu(IniFile, MenuItem, Items[i].Value);
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
Var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create('contextmenu.ini');
//SaveMenu(IniFile, PopupMenu1.Items,'PopupMenu1');
LoadMenu(IniFile, PopupMenu2.Items,'PopupMenu1');
end;
end.
__________________
Жизнь такова какова она есть и больше никакова.
Помогаю за спасибо.
|