我想簡化一下表單狀態到磁盤的保存。我使用從TIniFile派生的我自己的INI文件類來讀取表單的「所有」控件的狀態。事情是這樣的:TAction.OnExecute沒有執行
procedure TMyIniFile.Read(Comp: TComponent);
begin
if ValueExists(Section, Comp.Name) then
begin
if Comp.InheritsFrom(TAction)
then TAction(Comp).Checked:= ReadBool(Section, Comp.Name, FALSE)
else
if Comp.InheritsFrom(TCheckBox) etc
end;
end;
我用我的課是這樣的:
TYPE
TformTester = class(TForm)
MyAction: TAction;
procedure actMyActionExecute(Sender: TObject);
...
procedure TformTester.FormDestroy(Sender: TObject);
VAR
MyIniFile: TMyIniFile;
begin
MyAction.Checked:= true;
MyIniFile:= TMyIniFile.Create('Main Form');
MyIniFile.write(MyAction); // <------ This saves the 'Checked' property of MyAction.
...
end;
我驗證INI文件和國家的正確保存(真/假),取決於在關閉屬性的狀態下。
procedure TformTester.FormStartUp;
VAR MyIniFile: TMyIniFile;
begin
MyIniFile:= TMyIniFile.Create('Main Form');
MyIniFile.read(MyAction); // <------ This reads the 'Checked' property of MyAction. It should execute the actMyActionExecute but it doesn't.
assert(MyAction.Checked); // <---- Yes, it is checked
...
end;
procedure TformTester.MyActionExecute(Sender: TObject);
begin
if MyAction.Checked
then Caption:= 'Action checked'
else Caption:= 'Action is un-checked!';
end;
問:爲什麼執行MyIniFile.read(MyAction)時actMyActionExecute不叫?
PS:MyIniFile.read(MyCheckbox)的作品,如果我不通過其他任何東西,例如複選框。我的意思是MyCheckbox.OnClick被執行!
MyAction.AutoCheck爲True; – Ampere