Closed windows storing their values ​​/ selection

I have an application that takes several different forms. From the main form, I can open several other forms, I use the following command to display the selected window:

frmConversions.ShowModal; 

As soon as the user completes what they need to do in this window and they close this window, I will close the window using the following:

 frmConversions.Close; 

However, if the user returns to frmConversions, the settings they previously selected will still be selected / entered. I process several windows correctly, and if so, how can I stop saving data?

+4
source share
3 answers

It depends on how you create the form. If you automatically create a form, then it will exist for the lifetime of the program and therefore will save any values ​​stored in the form variables. If, however, you create modal forms when necessary and release them later (as is customary), then the values ​​will not be saved. This is done in this way.

 with TFrmConversions.Create(nil) do try ShowModal; finally Free; end; 
+10
source

In the FormClose event, you can choose what happens to the form when Close is called (see the documentation here too . If the action is for example caHide, the form is hidden and not freed, and thereby it will perform settings.

+1
source

There are two main approaches: 1) create a form each time until it is shown, and free it when it is closed. 2) in the OnShow form of the event, set all the variables that the user can change to their initial values.

Execution Method # 1 is to put the function in the form unit file, to create it, showmodal, and then free it.

0
source

Source: https://habr.com/ru/post/1389892/


All Articles