Материал: Мансуров. Основы программирования в среде Lazarus. 2010

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

Глава 6 Программирование приложений с графическим интерфейсом

____________________________________________________________________

// установка свойств ListView1 with ListView1 do

begin

Align:= alClient;

ViewStyle:= vsReport;

Columns.Add;

Columns.Items[0].Width:= 425;

ScrollBars:= ssAutoBoth;

SmallImages:= ImageList1;

end;

end;

procedure TForm1.Show_Only_Dir(ParentNode: TTreeNode); var

srNode, srChild: TSearchRec; Node: TTreeNode; searchMask: string;

begin

Node:= ParentNode; path:= '';

repeat

{$IFDEF WINDOWS}

path:= UTF8ToSys(Node.Text) + '\' + path; {$ELSE}

path:= '/' + Node.Text + '/' + path; {$ENDIF}

Node:= Node.Parent; until Node = nil;

if FindFirst(path + '*', faDirectory, srNode) = 0 then

691

6.3 Визуальное программирование в среде Lazarus

____________________________________________________________________

repeat

if (srNode.Attr and faDirectory <> 0) and Real_Directory(srNode.Name) then

begin

Node:= TreeView1.Items.AddChild(ParentNode,

SysToUTF8(srNode.Name));

Node.ImageIndex:= 0;

Node.SelectedIndex:= 0;

{$IFDEF WINDOWS}

searchMask:= path + srNode.Name + '\*'; {$ELSE}

searchMask:= path + srNode.Name + '/*'; {$ENDIF}

if FindFirst(searchMask, faDirectory, srChild) = 0 then

repeat

if (srChild.Attr and faDirectory <> 0) and Real_Directory(srChild.Name)

then Node.HasChildren:= true;

until (FindNext(srChild) <> 0) or Node.HasChildren; SysUtils.FindClose(srChild);

end;

until FindNext(srNode) <> 0; SysUtils.FindClose(srNode);

end;

procedure TForm1.Show_in_ListView_Dir(ParentNode: TTreeNode);

var

692

Глава 6 Программирование приложений с графическим интерфейсом

____________________________________________________________________

srNode, srChild: TSearchRec; Node: TTreeNode;

ListItem: TListItem; searchMask: string;

begin

Node:= ParentNode; path:= '';

repeat

{$IFDEF WINDOWS}

path:= UTF8ToSys(Node.Text) + '\' + path; {$ELSE}

path:= '/' + Node.Text + '/' + path; {$ENDIF}

Node:= Node.Parent; until Node = nil;

if FindFirst(path + '*', faDirectory, srNode) = 0 then repeat

if (srNode.Attr and faDirectory <> 0) and Real_Directory(srNode.Name) then

begin

Node:= TreeView1.Items.AddChild(ParentNode,

SysToUTF8(srNode.Name));

if srNode.Attr and faHidden = 0 then begin

ListItem:= ListView1.Items.Add;

ListItem.Caption:= Node.Text;

ListItem.ImageIndex:= 0;

end;

{$IFDEF WINDOWS}

693

6.3 Визуальное программирование в среде Lazarus

____________________________________________________________________

searchMask:= path + srNode.Name + '\*'; {$ELSE}

searchMask:= path + srNode.Name + '/*'; {$ENDIF}

if FindFirst(searchMask, faDirectory, srChild) = 0 then

repeat

if (srChild.Attr and faDirectory <> 0) and Real_Directory(srChild.Name)

then Node.HasChildren:= true;

until (FindNext(srChild) <> 0) or Node.HasChildren; SysUtils.FindClose(srChild);

end;

until FindNext(srNode) <> 0; SysUtils.FindClose(srNode);

end;

procedure TForm1.Show_in_ListView_Files(ParentNode: TTreeNode);

var

srNode: TSearchRec; Node: TTreeNode; ListItem: TListItem;

begin

Node:= ParentNode; path:= '';

repeat

{$IFDEF WINDOWS}

path:= UTF8ToSys(Node.Text) + '\' + path;

694

Глава 6 Программирование приложений с графическим интерфейсом

____________________________________________________________________

{$ELSE}

path:= '/' + Node.Text + '/' + path; {$ENDIF}

Node:= Node.Parent; until Node = nil;

if FindFirst(path + '*', faAnyFile, srNode) = 0 then repeat

if srNode.Attr and faDirectory = 0 then begin

if srNode.Attr and faHidden = 0 then begin

ListItem:= ListView1.Items.Add;

ListItem.Caption:= SysToUTF8(srNode.Name);

ListItem.ImageIndex:= 1;

end;

end;

until FindNext(srNode) <> 0; SysUtils.FindClose(srNode);

end;

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);

begin

if Node = nil then exit; TreeView1.BeginUpdate; ListView1.BeginUpdate; ListView1.Clear; Node.DeleteChildren; Show_in_ListView_Dir(Node);

695

Смотрите также:

11 Горм +
113
14
1433
1511
1632
199
204
2N4264RE
3773