user863551
user863551

Reputation:

Closed Windows Retaining Their Values/Choices

I have an application that has a few different forms. From the main form I can open a number of other forms, I use the following command to display the chosen window:

frmConversions.ShowModal;

Once the user has completed what they need to do in that window and they close that window I close the window using the following:

frmConversions.Close;

However if the user then goes back to frmConversions, the settings that they had previously chosen will still be selected/entered. Am I handling multiple windows correctly and if so how do I stop the retention of data?

Upvotes: 4

Views: 180

Answers (3)

crefird
crefird

Reputation: 1610

There are two basic approaches: 1) create the form each time before it is shown and free it when it is closed. 2) in the form's OnShow event, set all the variables the user might change to their initial values.

A way to accomplish #1 is to put a function in the form's unit file to create it, showmodal, then free it.

Upvotes: 0

user160694
user160694

Reputation:

IN the FormClose event, you can choose what happens to the form when you call Close (see the documentation and here. If the Action is for example caHide, the form is hidden, not freed. And thereby it will mantain the settings.

Upvotes: 1

No'am Newman
No'am Newman

Reputation: 6477

It depends on how you create the form. If you auto-create the form, then it will exist for the lifetime of the program and so will retain any values stored in the form's variables. If, however, you create modal forms whenever needed and free them afterwards (as is the custom), then values will not be stored. This is done thus

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

Upvotes: 9

Related Questions