procedure TFileListBox.ReadFileNames; var AttrIndex: TFileAttr; I: Integer; FileExt: string; MaskPtr: PChar; Ptr: PChar; AttrWord: Word; FileInfo: TSearchRec; SaveCursor: TCursor; Glyph: TBitmap; const Attributes: array[TFileAttr] of Word = (faReadOnly, faHidden, faSysFile, faVolumeID, faDirectory, faArchive, 0); begin { if no handle allocated yet, this call will force one to be allocated incorrectly (i.e. at the wrong time. In due time, one will be allocated appropriately. } AttrWord := DDL_READWRITE; if HandleAllocated then begin { Set attribute flags based on values in FileType } for AttrIndex := ftReadOnly to ftArchive do if AttrIndex in FileType then AttrWord := AttrWord or Attributes[AttrIndex]; ChDir(FDirectory); { go to the directory we want } Clear; { clear the list } I := 0; SaveCursor := Screen.Cursor; try MaskPtr := PChar(FMask); while MaskPtr <> nil do begin Ptr := StrScan (MaskPtr, ';'); if Ptr <> nil then Ptr^ := #0; if FindFirst(MaskPtr, AttrWord, FileInfo) = 0 then begin repeat { exclude normal files if ftNormal not set } if (ftNormal in FileType) or (FileInfo.Attr and AttrWord <> 0) then if FileInfo.Attr and faDirectory <> 0 then begin FileInfo.Time//这个是文件时间,这个地方判断一下 I := Items.Add(Format('[%s]',[FileInfo.Name])); if ShowGlyphs then Items.Objects[I] := DirBMP; end else begin FileExt := AnsiLowerCase(ExtractFileExt(FileInfo.Name)); Glyph := UnknownBMP; if (FileExt = '.exe') or (FileExt = '.com') or (FileExt = '.bat') or (FileExt = '.pif') then Glyph := ExeBMP; I := Items.AddObject(FileInfo.Name, Glyph); end; if I = 100 then Screen.Cursor := crHourGlass; until FindNext(FileInfo) <> 0; FindClose(FileInfo); end; if Ptr <> nil then begin Ptr^ := ';'; Inc (Ptr); end; MaskPtr := Ptr; end; finally Screen.Cursor := SaveCursor; end; Change; end; end;
TFileListBox = class(TCustomListBox)
procedure TFileListBox.ReadFileNames;
var
AttrIndex: TFileAttr;
I: Integer;
FileExt: string;
MaskPtr: PChar;
Ptr: PChar;
AttrWord: Word;
FileInfo: TSearchRec;
SaveCursor: TCursor;
Glyph: TBitmap;
const
Attributes: array[TFileAttr] of Word = (faReadOnly, faHidden, faSysFile,
faVolumeID, faDirectory, faArchive, 0);
begin
{ if no handle allocated yet, this call will force
one to be allocated incorrectly (i.e. at the wrong time.
In due time, one will be allocated appropriately. }
AttrWord := DDL_READWRITE;
if HandleAllocated then
begin
{ Set attribute flags based on values in FileType }
for AttrIndex := ftReadOnly to ftArchive do
if AttrIndex in FileType then
AttrWord := AttrWord or Attributes[AttrIndex]; ChDir(FDirectory); { go to the directory we want }
Clear; { clear the list } I := 0;
SaveCursor := Screen.Cursor;
try
MaskPtr := PChar(FMask);
while MaskPtr <> nil do
begin
Ptr := StrScan (MaskPtr, ';');
if Ptr <> nil then
Ptr^ := #0;
if FindFirst(MaskPtr, AttrWord, FileInfo) = 0 then
begin
repeat { exclude normal files if ftNormal not set }
if (ftNormal in FileType) or (FileInfo.Attr and AttrWord <> 0) then
if FileInfo.Attr and faDirectory <> 0 then
begin
FileInfo.Time//这个是文件时间,这个地方判断一下
I := Items.Add(Format('[%s]',[FileInfo.Name]));
if ShowGlyphs then
Items.Objects[I] := DirBMP;
end
else
begin
FileExt := AnsiLowerCase(ExtractFileExt(FileInfo.Name));
Glyph := UnknownBMP;
if (FileExt = '.exe') or (FileExt = '.com') or
(FileExt = '.bat') or (FileExt = '.pif') then
Glyph := ExeBMP;
I := Items.AddObject(FileInfo.Name, Glyph);
end;
if I = 100 then
Screen.Cursor := crHourGlass;
until FindNext(FileInfo) <> 0;
FindClose(FileInfo);
end;
if Ptr <> nil then
begin
Ptr^ := ';';
Inc (Ptr);
end;
MaskPtr := Ptr;
end;
finally
Screen.Cursor := SaveCursor;
end;
Change;
end;
end;