Thanks for suggestion - what I have done is move the deletion of files routine back to the main program and exposed the progress bar and label I need to update through as properties.
Added a public procedure to decrement the progress bar which when it reached zero closed the form. This seems to work fine. Thanks for your help JohnB -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Luthfi Hakim Sent: 03 September 2007 14:17 To: [email protected] Subject: Re: Closing modal forms (John Barrat) Hello, The main problem is you used OnActivate event to do the hard work. The "ModalResult := mrOk" has no effect there. Maybe the best solution is using tread. Like this: type TFilesRemover = class(TThread) private procedure DoBeforeRemoval; procedure DoDisplayFileName; procedure DoProgress; procedure DoAfterRemoval; protected procedure Execute; override; end; procedure TFilesRemover.Execute; begin FindFilesToDelete; Synchronize(DoBeforeRemoval); for i := 0 to FileList.Count-1 do begin Synchronize(DoDisplayFileName); if DeleteFile(FileList[i])then Synchronize(DoProgress); end; Synchronize(DoAfterRemoval); end; procedure TFilesRemover.DoBeforeRemoval; begin ProgressBar1.Max := FileList.Count; ProgressBar1.Min := 0; ProgressBar1.Position := ProgressBar1.Max; end; procedure TFilesRemover.DoDisplayFileName; begin Label1.Caption := '"'+ ExtractRelativePath(IDEPath,FileList[i]) + '"'; end; procedure TFilesRemover.DoProgress; begin ProgressBar1.Position := ProgressBar1.Position - 1; end; procedure TFilesRemover.DoAfterRemoval; begin Label1.Caption := 'Done'; fmProgress.ModalResult := mrOK; end; and you call the thread in OnShow event of fmProgress like this: procedure TfmProgress.OnShow(Sender: TObject); begin // create suspended with TFilesRemover.Create(True) do begin // fire and forget FreeOnTerminate := Free; Resume; end; end; Cheers! Luthfi B Hakim > My FormActivate code is shown below. Although I set the modal result > to > mrOK the form fails to close. On Mon, 03 Sep 2007 20:18:09 +0100, Luthfi B Hakim <[EMAIL PROTECTED]> wrote: > Can someone explain what I am doing wrong? > > I have a form which is there simply to report progress - it has a > progressbar on it. > This is how I am calling it: > > procedure TfmCleanUpMain.btnOKClick(Sender: TObject); > begin > if fmprogress.showmodal <> mrNone then > close; > end; > > On its return I close the application. > > I do all the work on the progress form in the OnActivate event. - this > may > be my problem but I don't know a way around it as there is no user > interaction with the form. > > My FormActivate code is shown below. Although I set the modal result > to > mrOK the form fails to close. > > procedure TfmProgress.FormActivate(Sender: TObject); Var i: Integer; > begin > FindFilesToDelete; > ProgressBar1.Max := FileList.Count; > ProgressBar1.Min := 0; > ProgressBar1.Position := ProgressBar1.Max; > For i := 0 to FileList.Count -1 do > begin > Label1.Caption := '"'+ ExtractRelativePath(IDEPath,FileList[i]) + > '"'; > if DeleteFile(FileList[i])then > ProgressBar1.Position := ProgressBar1.Position - 1; > end; > Label1.Caption := 'Done'; > fmProgress.ModalResult := mrOK; > end; > > Can anyone suggest a solution? > > JohnB Vorelsoft, Top Quality Software PhiDesktop, Multi Virtual Desktop, add unlimited monitor to your PC ____________________________________________________________________________ ________ Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433 _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

