Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Form Creation

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I've been using the following technique for creating forms on the fly:

Code:
with TfrmAddVenire.Create(frmMain) do
begin
  dtNewVenireEnd := IncYear(dtLastEnteredVenire, 1);
  while dtLastEnteredVenire < dtNewVenireEnd do
  begin
    dtLastEnteredVenire := IncWeek(dtLastEnteredVenire, 2);
    lbVenireDates.Lines.Add(FormatDateTime('MM/DD/YYYY', dtLastEnteredVenire));
  end;
  Show;
end;

When frmAddVenire is done being used and is closed, is it automatically destroyed as well or do I need to do that in a separate step?

Thanks!

Leslie
 
The best way to free the resources used by a dynamically created form is to set the Action in the OnClose event handler to caFree.

So your OnClose event handler may look something like this:
Code:
procedure TForm2.FormClose(Sender: TObject; var Actin: TCloseAction);
begin
 if MessageDlg('OK to close?', mtConfirmation,[mbYes,mbNo], 0) = mrYes then
 Action := caFree
else
 Action := caNone;
end;
There are several useful things you can do in he OnClose handler such as checking that files or registry records have been updated and so on.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top