If you look at the FillFromDirectory code you will see that there are no provisions to abort the 'Fill' in the current version. The current version only breaks when you set a limit on the number of files to be loaded.
if (Limit>-1) and (count=limit) then
break;
So if you get a count on the number of images in the folder you can call FillFromDirectory with limits or allow the user to load all the files anyway.
function GetFileCount(AFolder, AWildCard: string): Integer;
//Return the AFolder file count
var
iIntegerFound: Integer;
iSearchRec: TSearchRec;
begin
Screen.Cursor := crHourGlass;
try
Result := 0;
if (AFolder <> '') and (AFolder[Length(AFolder)] <> '\') then
AFolder := AFolder + '\';
iIntegerFound := FindFirst(AFolder + AWildCard, faAnyFile, iSearchRec);
while (iIntegerFound = 0) do
begin
if not (iSearchRec.Attr and faDirectory = faDirectory) then
Inc(Result);
iIntegerFound := FindNext(iSearchRec);
end;
FindClose(iSearchRec);
finally
Screen.Cursor := crDefault;
end;
end;
procedure TForm1.FillFromDirectory1Click(Sender: TObject);
var
iResult: integer;
iFileCount: integer;
iMax: integer;
iMessage: string;
begin
// Fill ImageEnMView with images from a folder
if DirectoryExists(AFolder) then
begin
iFileCount := GetFileCount(AFolder, '*');
iMax := StrToIntDef(Max1.Text, 5);
if iFileCount > iMax then
begin
iMessage := 'The Folder Has ' + IntToStr(iFileCount) + ' Files.' + #10#13 + #10#13 +
'Select "Yes" to load all files, select "No" to load ' + IntToStr(iMax) +
' files. Select "Cancel" to abort.';
iResult := MessageBox(0, PWideChar(iMessage),
'Add All Images', MB_ICONQUESTION or MB_YESNOCANCEL);
if iResult = idYes then
iMax := -1
else if iResult = idNo then
iMax := StrToIntDef(Max1.Text, 5)
else
exit;
end;
ImageEnMView1.Clear;
ImageEnView1.Clear;
iResult := MessageBox(0, 'Add supported image types only?' + #10#13 + #10#13 +
'If Yes then only known and supported file formats will be loaded, if No then all files will be loaded. If Cancel then abort.',
'Add Supported Images Only', MB_ICONQUESTION or MB_YESNOCANCEL);
if iResult = idYes then
begin
Caption := 'ImageEnMView Thumbnail Spacing From A To Z With DragAndDrop- All Supported Images In '
+ AFolder;
ImageEnMView1.FillFromDirectory(AFolder, iMax, False, '', True, '', False);
end
else if iResult = idNo then
begin
Caption := 'ImageEnMView Thumbnail Spacing From A To Z With DragAndDrop- All Supported Files In '
+ AFolder;
ImageEnMView1.FillFromDirectory(AFolder, iMax, True);
end
else if iResult = idCancel then
begin
Caption := 'ImageEnMView Thumbnail Spacing From A To Z With DragAndDrop';
exit;
end;
Screen.Cursor := crHourGlass;
try
ImageEnMView1.GridWidth := StrToIntDef(Columns1.Text, 3);
ImageEnMView1.Width := ((ImageEnMView1.ThumbWidth + ImageEnMView1.HorizBorder) *
ImageEnMView1.GridWidth) + ImageEnMView1.HorizBorder * 2;
ImageEnMView1.Update;
ImageEnMView1.SelectedImage := 0;
AFilename := ImageEnMView1.ImageFileName[0];
ImageEnView1.IO.LoadFromFile(AFilename);
if Fit1.Checked then
ImageEnView1.Fit;
ImageEnMView1.GridWidth := StrToIntDef(Columns1.Text, 3);
ImageEnMView1.Width := ((ImageEnMView1.ThumbWidth + ImageEnMView1.HorizBorder) *
ImageEnMView1.GridWidth) + ImageEnMView1.HorizBorder * 5;
ImageEnMView1.Update;
ImageEnView1.Bitmap.Modified := False;
StatusBar1.Panels[0].Text := ExtractFileDir(AFilename);
StatusBar1.Panels[1].Text := ExtractFileName(AFilename);
finally
Screen.Cursor := crDefault;
end;
end
else
MessageBox(0, PChar('The folder ' + AFolder + ' does not exist.'), 'Warning', MB_ICONWARNING or
MB_OK);
end;
William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html