Цитата:
Сообщение от dr. F.I.N.
Потому что Item: TCustomViewItem не является указателем на TSearchRec, и Ваше преобразование pFile:=PSearchRec(Item) не работает от слова "совсем".
Для получения атрибутов файла используйте FileGetAttr.
|
СПАСИБО.
Попробую, а пока решил таким вот образом, может кому пригодится:
1. Для выделения файлов списком в FileListView, его и составляем (List)
Код:
procedure TFileListViewColor.SelectFile(var Key: Word; Shift: TShiftState);
var
i:integer;
pFile:PSearchRec;
begin
if (PFileInfo(Selected.Data)^.SR.Attr and faDirectory = 0) then
begin
i:=list.IndexOf(inttostr(Selected.Index));
if (i=-1) then
begin
if (Directory.Location+items.Item[Selected.Index].Caption<>fileNameZaxvat) then
begin
list.Add(inttostr(Selected.Index));
Inc(FItemIndex);
fLengthFiles:=fLengthFiles+PFileInfo(Selected.Data)^.SR.size;
end;
end
else
begin
list.Delete(i);
Dec(FItemIndex);
fLengthFiles:=fLengthFiles-PFileInfo(Selected.Data)^.SR.size;
end;
Key:=4117;
inherited KeyDown(Key, Shift);
if Assigned(fOnSelectFile) then
fOnSelectFile(self);
end;
end;
и вызываем в KeyDown
Код:
procedure TFileListViewColor.KeyDown(var Key: Word; Shift: TShiftState);
var
i:integer;
begin
inherited KeyDown(Key, Shift);
if Key = Key_F5 then
Refresh;
if Key = Key_Insert then
SelectFile(Key, Shift);
if (Selected<>nil) then
if (Key=4117) then //Down
begin
DOWN_UP :=true;
i:=ItemFocused.Index;
if (i+1)<=Items.Count-1 then
FFileName:=Items.Item[i+1].Caption;
a_MCaption.Caption:=FFileName;
end;
if (Key=4115) then //Up
begin
DOWN_UP :=false;
i:=ItemFocused.Index;
if (i-1)>=0 then
FFileName:=Items.Item[i-1].Caption;
a_MCaption.Caption:=FFileName;
end;
end;
2. При открытии папки или её обновлении составляем список listfiles_Attr атрибутов файлов:
Код:
procedure TFileListViewColor.Update;
var
i:integer;
pFile:PSearchRec;
begin
listfiles_Attr.Clear;
for i:=0 to Items.Count-1 do
begin
pFile:=Items.Item[i].Data;
listfiles_Attr.Add(pFile);
end;
end;
3. И отображаем по списку List -выделенные файлы и атрибуты файлов цветом (PSearchRec(Listfiles_Attr.Items[ListItem.Index]).Attr):
Код:
function TFileListViewColor.DoCustomDrawViewItem(Item: TCustomViewItem;
Canvas: TCanvas; const Rect: TRect; State: TCustomDrawState;
Stage: TCustomDrawStage): Boolean;
var
R: TRect; IL: TCustomImageList; ListItem: TListItem; i:integer;
pFile:PSearchRec;
FFileName_:string;
j: integer;
begin
Result := False;
if Stage = cdPostPaint then Result := inherited DoCustomDrawViewItem(Item, Canvas, Rect, State, cdPrePaint);
if Result then
begin
R := Rect;
Canvas.FillRect(R);
ListItem := TListItem(Item); //
if list.Count>0 then
begin
if DOWN_UP then
i:=Selected.Index-1
else
i:=Selected.Index+1;
if (isSelect(i)) then
begin
Canvas.Brush.Color :=Color;
Canvas.Font.Color :=clLime;
end;
end
else
begin
Canvas.Brush.Color :=Color;
case PSearchRec(Listfiles_Attr.Items[ListItem.Index]).Attr of
faSysFile : Canvas.Font.Color:=clRed;
faHidden : Canvas.Font.Color:=clBlue;
faArchive : Canvas.Font.Color:=clBlack;
faAnyFile : Canvas.Font.Color:=clAqua;
end;
end;
with ListItem do
begin
if Assigned(Images) then
IL := Images
else
IL := FIconProvider;
Inc(R.Top, (R.Bottom - R.Top - IL.Height) div 2);
IL.Draw(Canvas, R.Left, R.Top, ImageIndex);
{$IFDEF LINUX}
if (Data <> nil) and (PFileInfo(Data).SR.Attr and faSymLink <> 0)
and (IL = FIconProvider) then
FIconProvider.DrawLinkOverlay(Canvas, R.Left, R.Top, PFileInfo(Data));
{$ENDIF}
Inc(R.Left, IL.Width + 2);
if (Data <> nil) and (EditingItem <> Item) then
DrawTruncatedText(Canvas, R, PFileInfo(Data).SR.Name)
else
Result := True;
end;
end;
if Stage = cdPostPaint then
begin
inherited DoCustomDrawViewItem(Item, Canvas, Rect, State, Stage);
Result := False;
end;
end;
Работает...
4.
И всё же может кто-то знает, как заставить FileListView показывать и скрытые файлы с атрибутом faHidden.
Они просто не видны в списке FileListView.
Так выглядит:
https://photos.google.com/photo/AF1Q...yREoi24pnLEYU6