Problem Closing Forms

Problem Closing Forms


I created the main search screen form SearchScrn (fsNormal) with the ability to create as many new forms on the fly (they are not children of MDI form) as possible after a search is refined. I can close all of these forms using one button click event:

procedure TSearchScrn.CloseAllBtnClick(Sender: TObject);beginSearchScrn.Close;end;  { TSearchScrn.CloseAllBtnClick }

This works, but if I want to start new search, I try to close all forms and create a new main SearchScrn form:

procedure TSearchScrn.SearchListBtnClick(Sender: TObject);var  SearchStr1     : String[20];  SearchOp       : String[ 3];  SearchStr2     : String[20];begin  if Pos('New',SearchListBtn.Caption)>0 then     begin     SearchStr1:=SearchFld.AsString;     SearchOp  :=SearchOperator.Text;     SearchStr2:=SearchFld2.AsString;     SearchScrn.Close;     SearchScrn := TSearchScrn.Create( Self );     with SearchScrn do          begin          SearchFld.AsString:=SearchStr1;          SearchOperator.Text:=SearchOp;          SearchFld2.AsString:=SearchStr2;          MakeSearch;          ShowModal;          end;     end     else       MakeSearch;end;  { TSearchScrn.SearchBtnClick }

For some reason SearchScrn.Close does not close all the forms and instead leaves them on the screen.

One thing that you should do is to ‘Free’ the form after closing it. Also, to make doubly sure that the form variable’s reference is gone, set it to ‘nil’ after freeing it.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular