I'm not sure addressing this issue again is valuable enough, but I'd like to share my idea and experiements with others.
First of all, I appreciate all the comments and commenters.
My baseline purpose is the content in the controls are saved to a field in object, like
type
TMyObject = class
published
Name,
Address : string;
OtherInfo: TStringList;
// methods
end;
TMyFrame = class (TFrame)
edit1 : TTIEdit; // name
edit2 : TTIEdit; // address
OtherInfoEdit : TValueListEditor;
// methods
private
FMyObject : TMyObject;
procedure setMyObject(AValue: TMyObject);
public
property MyObject : TMyObject read FMyObject write setMyObject;
end;
implementation
procedure TMyFrame.setMyObject(AValue: TMyObject);
begin
if AValue <> nil then begin
FMyObject := AValue;
OtherInfoEdit.Strings.Text := FMyObject.OtherInfo.Text; // initialize the content of valuelist editor
end;
end;
I do not assign any saving procedure myself for RTTI controls. But I have to write them for general controls, TValueListEditor here. So,
procedure TMyFrame.OtherInfoEditEditingDone(sender: TObject); // or
procedure TMyFrame.OtherInfoExit(sender: TObject); // either one is the same
begin
MyObject.OtherInfo.Text := OtherInfoEdit.Strings.Text;
end;
And I want the (changed) contents in the controls are automatically saved in the MyObject variable. The contents are saved when focus moves from one control to another, but not (neither RTTI controls nor general controls, neither OnEditingDone nor OnExit) when I leave the form like by running other Windows application, by closing the form pressing Alt-F4 or small x, or on other cases I do not remember exactly. So I was looking for ways that I can save my changes reliably, i.e. will call OnExit or OnEditingDone reliably.
I thought over solutions suggested here in comments. But I think it better not to introduce any futher things like TWinControl or TNotifyEvent or other event handlers or new variable like ParentForm.
And I found putting ActiveContol to nil in the form.
procedure TMyForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
// It is possible to ask whether to save the changes here, but decided to put it later setp, between Object and permanent storage (e.g. database)
Self.ActiveControl := nil;
end;
This will call OnExit or OnEditingDone procedures defined only in the frames.
Hope that I did not mislead you by the title ".. when form is clicked?". At first, I tried to save the content by clicking on (title bar or vacant part of) the form but I found that there are other situations like pressing Alt-F4.
Thank all of you again for your kind advices.