У меня следующая проблема, которая меня заставляет бить в бубен уже неделю.
Программа - файловый менеджер, имеет главное меню, в котором несколько кнопок с checkbox (скрытые, системные, только чтение). Если поставлена галочка файлы отображаются в противном случае нет. Это в теории, на практике readonly файлы клали на мои попытки, в отличие от остальных. Хотелось бы узнать почему.
код:
Код:
var attributes:integer;
procedure TForm1.AttrHClick(Sender: TObject);
begin
attributes:=attributes xor fahidden;
addfile(dir+'*.*',attributes)
end;
procedure TForm1.AttrRClick(Sender: TObject);
begin
attributes:=attributes xor fareadonly;
addfile(dir+'*.*',attributes)
end;
procedure TForm1.AttrSClick(Sender: TObject);
begin
attributes:=attributes xor fasysfile;
addfile(dir+'*.*',attributes)
end;
function TForm1.AddFile(FileMask: string; FFileAttr: DWORD): Boolean;
var Shlnfo: tshfileinfo;
attributes: string;
FileName: string;
hFindFile: THandle;
SearchRec: TSearchRec;
function AttrStr(Attr: integer): string;
begin
Result:='';
if (FILE_ATTRIBUTE_ARCHIVE and Attr)>0 then Result:=Result + 'A' else result:=result+'-';
if (FILE_ATTRIBUTE_HIDDEN and Attr)>0 then Result:=Result + 'H' else result:=result+'-';
if (FILE_ATTRIBUTE_READONLY and Attr)>0 then Result:=Result + 'R' else result:=result+'-';
if (FILE_ATTRIBUTE_SYSTEM and Attr)>0 then Result:=Result + 'S' else result:=result+'-';
end;
begin
listview1.Items.BeginUpdate;
listview1.Items.Clear;
Result:=false;
hFindFile:=FindFirst(FileMask, FFileAttr, SearchRec);
if hFindFile <> INVALID_HANDLE_VALUE then
try
repeat
with SearchRec.FindData do
begin
if (SearchRec.Name = '.') or (SearchRec.Name = '') then continue;
FileName:=slashsep(dir, SearchRec.Name);
{добавляет \ между путём и файлом}
SHGetFileInfo(PChar(FileName), 0, Shlnfo, SizeOf(Shlnfo),
SHGFI_TYPENAME or SHGFI_SYSICONINDEX);
Attributes:=AttrStr(dwFileAttributes);
with listview1.Items.add do
begin
if (FILE_ATTRIBUTE_DIRECTORY and dwFileAttributes)=0
then
begin
Caption:=getfilename(searchrec);
imageindex:=GetIconIndex('.'+getfileextension(searchrec));
if getfileextension(searchrec)='' then imageindex:=0;
subitems.Add(getfileextension(searchrec));
subitems.Add(getfilesize(SearchRec));
subitems.Add(FileTimeToDateTimeStr(ftLastwriteTime));
{преобразует время в строку}
subitems.Add(attributes)
end
else
begin
caption:='['+searchrec.Name+']';
imageindex:=1;
if searchrec.Name='..' then imageindex:=5;
subitems.Add('Папка');
subitems.Add('');
subitems.Add(FileTimeToDateTimeStr(ftLastwriteTime));
subitems.Add(attributes)
end;
end;
Result:=true;
end;
until (FindNext(SearchRec) <> 0);
sortdir(listview1);
finally
FindClose(SearchRec);
end;
listview1.Items.EndUpdate
end;