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!

form that won't close

Status
Not open for further replies.

DaZZleD

Programmer
Oct 21, 2003
886
US
when starting my application I create a form at runtime that contains a progress bar indicating the percent of data loaded from the DB. at the end of the loading, the main form displays and this temporary form is being closed. the problem is that when runing from delphi with F9 all is ok (the temp form is closed) while when runing from explorer like any other executable, if i change focus to another window (while the tempForm is being displayed), the temp form won't close anymore. i added a timer in the main form that checks for the existance of the tempForm and closes it if it's open but with no result.

the code is:
Code:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
     if tempForm <> nil then
     begin
          tempForm.Close;
          form1.Timer1.Enabled := false;
     end;
end;

if I simply add a showmessage inside the if clause, everything works ok. this is kind of annoying since this tempForm won't even close when the 'X' button is pressed.

any help is greatly appreciated.
 
Can you show the code you're using to create your form?

DjangMan
 
Code:
procedure TForm1.InitData();
begin
     // i have declared all tempForm and its components as private in form1

     tempForm := TForm.CreateNew(self);
     tempPBar := TProgressBar.Create(tempForm);
     tempPTBar := TProgressBar.Create(tempForm);
     tempLabel := TLabel.Create(tempForm);
     tempTLabel := TLabel.Create(tempForm);

     tempForm.Width := 400;
     tempForm.Height := 120;
     tempForm.Position := poScreenCenter;
     tempForm.Caption := 'Please Wait';
     tempForm.AutoScroll := false;
     tempForm.FormStyle := fsStayOnTop;
     tempForm.BorderStyle := bsSingle;
     tempForm.InsertControl(tempPBar);
     tempForm.InsertControl(tempPTBar);
     tempForm.InsertControl(tempLabel);
     tempForm.InsertControl(tempTLabel);

     tempTLabel.Left := 25;
     tempTLabel.Top := 5;
     tempTLabel.Layout := tlCenter;
     tempTLabel.Caption := 'Percent Done';
     tempTLabel.Width := 350;
     tempTLabel.Alignment := taCenter;
     tempTLabel.Visible := true;

     tempPTBar.Width := 350;
     tempPTBar.Height := 10;
     tempPTBar.Top := 20;
     tempPTBar.Left := 25;
     tempPTBar.Visible := true;

     tempPBar.Width := 350;
     tempPBar.Height := 10;
     tempPBar.Top := 47;
     tempPBar.Left := 25;
     tempPBar.Visible := true;

     tempLabel.Height := 20;
     tempLabel.Left := 25;
     tempLabel.Top := 60;
     tempLabel.Layout := tlCenter;
     tempLabel.Caption := 'Starting Application';
     tempLabel.Width := 350;
     tempLabel.Alignment := taCenter;
     tempLabel.Visible := true;

     tempForm.Visible := true;
     tempForm.Repaint;

     tempLabel.Caption := 'Initialising';
     tempForm.Repaint;

     form1.InitDB();

     tempLabel.Caption := 'Citesc Options';
     tempForm.Repaint;

     form1.ReadOptions();

     tempLabel.Caption := 'Reading Data';
     tempForm.Repaint;

     form1.ReadRed();
     form1.ReadPrg();
     form1.ReadAng();

     tempLabel.Caption := 'Ending';
     tempForm.Repaint;
  
   // refresh forms control (enable/disable controls...etc)
   form1.refreshData;

   if tempForm<>nil then
        tempForm.Close;
end;
 
In the OnClose event handler of tempForm, do you have:

action := caFree;

If not try doing either that or change your final If statement to:

if tempForm<>nil then
begin
tempForm.Close;
FreeAndNil(tempForm);
end;

-D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top