procedure TMainForm.FormDestroy(Sender: TObject);
var
Registry: TRegistry;
begin
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey('...', True) then
begin
Registry.WriteInteger('MainLeft', Self.Left);
Registry.CloseKey;
end;
finally
Registry.Free;
end;
end;
Similar code works for FormCreate, but not when the application is closed (i.e. nothing is saved to the registry). What am I missing?
P.S. The '...' stands for the registry key name. Since it works for FormCreate, I don't think it's an issue.
P.P.S. If I add MainForm.Destroy to the program code:
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
MainForm.Destroy;
end.
nothing changes. If I also set FormDestroy as MainForm's OnDestroy event, I get "Access violation" error upon closing the application.
It's all very confusing :-)