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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShowModal form not displaying until after disk IO is finished

Status
Not open for further replies.

NelsonN

Programmer
May 5, 2003
3
PR
I have an application that I wrote in Delphi 3 Standard and it has a form which I show in Modal that has a cancel button, exit button, an edit box where all the files that are being processed are displayed, and a status bar.

This works fine in Delphi 3 Standard but not with Delphi 7 Enterprise. I know it has something to do with the disk IO, like when it is searching for folders and files. Only after this process is finished does the form show.

The About form is being displayed as ShowModal so I know it isn't this. I have tried adding Application.ProcessMessages everywhere, especially in between the FindNext and FindFirst procedures/functions to try and find the problem but no luck.
 
I switched to using a component for searching for the files, I still have the same problem. This is the FormShow event of the form that is supposed to update the progress status displays. Like I said, works fine with Delphi 3 Standard.

procedure TProgressForm.FormShow(Sender: TObject);
var ext: string;
c : integer;
begin
SearchResult := TStringList.Create;
SearchResult.Clear;
Screen.Cursor := crHourglass;
MainForm.StatusWindow.Clear;
MainForm.ClientHeight := 525; { show status window }
ProgressForm.StopButton.Caption := 'Stop';
CancelProcess := False;
AbortProcess := False;
TotalFilesFound := 0;
Application.ProcessMessages;
ProgressForm.TotalProgressBar.Position := 0;
ProgressForm.ProcessingFilesMemo.Clear;

SetFocus;

ProgressForm.EasyFileSearch1.FileNames.Clear;

ProgressForm.EasyFileSearch1.RootPath := MainForm.SelectedDirectoryCombobox.Text;

{ Initialize search criteria }
with ProgressForm.EasyFileSearch1 do
begin
SearchOptions := [];
if MainForm.SearchSubdirsCheckBox.Checked=True then SearchOptions := SearchOptions + [okIncludeSubfolder ];
SearchOptions := SearchOptions + [okLookForReadOnlyFile];
SearchOptions := SearchOptions + [okLookForArchiveFile ];
SearchOptions := SearchOptions + [okLookForAnyFile ];
end;

ext := MainForm.FilterExtensionsComboBox.Text;
Repeat
//SetLength(Result, Length(Result)+ 1);
C:= Pos(';', ext);
If C = 0 Then C := Length(ext) + 1;
//Result[Length(Result)- 1]:= Copy(S, 1, C- 1);
//vidal code: mFileScan1.Filters.Add(Copy(ext, 1, C- 1));
ProgressForm.EasyFileSearch1.FileNames.Add(Copy(ext, 1, C- 1));
Delete(ext, 1, C);
Until Length(ext) = 0;

if MainForm.GreedyCheckBox.Checked then
RegExprModifierG := True
else
RegExprModifierG := False;

if MainForm.ModifierSlashMCheckBox.Checked then
RegExprModifierM := True
else
RegExprModifierM := False;

if MainForm.ModifierSlashSCheckBox.Checked then
RegExprModifierS := True
else
RegExprModifierS := False;

if MainForm.ModifierSlashXCheckBox.Checked then
RegExprModifierX := True
else
RegExprModifierX := False;

StartTime := now;
MainForm.StatusWindow.Lines.Add('>> Starting process: ' + DateTimeToStr(StartTime));
ProgressForm.ProcessingFilesMemo.Lines.Add('>> Starting process: ' + DateTimeToStr(StartTime));
MainForm.StatusWindow.Lines.Add('>> Scanning directory(ies) for files...');
ProgressForm.ProcessingFilesMemo.Lines.Add('>> Scanning directory(ies) for files...');
Application.ProcessMessages;

if ProgressForm.EasyFileSearch1.Search=False then
begin
//Application.ProcessMessages;
MessageBox(Handle, 'Error during the search operation !', 'ERROR', 0);
end
else
begin
Application.ProcessMessages;
ProcessFoundFiles;
end;
end;
 
I fixed the problem, it seems Delphi 7 prefers that I place that code in the OnFormPaint event procedure of the form, instead of the OnShow event procedure.

procedure TProgressForm.FormPaint(Sender: TObject);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top