I am using Delphi 7 and trying to create Delphi application having 5 buttons on Main Form. Each button click will display another form with some components on it. The most components on subform for all button clicks are same. Which will be better way to do:
-
to create new form on each click and and destroy it when it closed
or
-
to create one form once and use the same form for others (using directly
ShowModal)?
But the problem in 2nd option is when I show that subform on 2nd time then the values of form remains same as when entered first time. Any solution to refresh it quickly?? or any other solution to display form?
The problem is that these forms are already auto-created when you add them to your app. You only need to create one of these, and remove its auto-creation.
Go to Project > Options > Forms tab and look at the list of ‘Auto-Create forms’. Remove your sub-form from this list (adding it to the list on the right of ‘available forms’).
Now you don’t need to create 5 different forms if you are showing them as modal, especially. You just need one…
Unit1
5
TButtoncontrols, all sharing the sameButtonClickevent (for this example) and whatever other controls you wish…Note that I never once refer to the name
Form2. Instead, I temporarily declareF: TForm2just for the duration that I need it. If it wasn’t going to be modal, you would need a far different approach.