What' mistake in code?
var
SearchRec: TSearchRec;
SearchResults: Integer;
ImagesList: TStringList;
MyRnd : Integer;
begin
ImagesList:= TStringList.Create;
try
Path:= '?:\MySuperDir\MySuperSubDir\';
SearchResults := FindFirst(Patch + '*.bmp', faAnyFile, SearchRec);
while SearchResults = 0 do
begin
if SearchRec.Attr <> faDirectory then ImagesList.Add(Patch + SearchRec.Name);
SearchResults := FindNext(SearchRec);
end;
FindClose(SearchRec);
if ImagesList.Count > 0 then
begin
Randomize;
MyRnd := Random(ImagesList.Count);
Image1.Picture.LoadFromFile(ImagesList[MyRnd]);
end;
finally
FreeAndNil(ImagesList);
end;
end;
Help me, please
|