frmResTree.pas
上传用户:youjie821
上传日期:2013-01-27
资源大小:459k
文件大小:3k
- unit frmResTree;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, hxFileRes, StdCtrls, ComCtrls, FileCtrl, hxClasses, ActnList, CSIntf;
- type
- TResTreeForm = class(TForm)
- TreeView1: TTreeView;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- ActionList1: TActionList;
- actLoad: TAction;
- actAdd: TAction;
- actDelete: TAction;
- Label1: TLabel;
- Button4: TButton;
- actRefresh: TAction;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure actLoadExecute(Sender: TObject);
- procedure actDeleteUpdate(Sender: TObject);
- procedure actDeleteExecute(Sender: TObject);
- procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
- procedure actRefreshExecute(Sender: TObject);
- private
- { Private declarations }
- FResTree: TResTree;
- procedure RefreshTreeView(TreeView: TTreeView; Tree: TResTree);
- public
- { Public declarations }
- end;
- procedure ShowResTreeForm;
- implementation
- {$R *.dfm}
- procedure ShowResTreeForm;
- begin
- with TResTreeForm.Create(nil) do
- try
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TResTreeForm.FormCreate(Sender: TObject);
- begin
- FResTree:= TResTree.Create;
- end;
- procedure TResTreeForm.FormDestroy(Sender: TObject);
- begin
- FResTree.Free;
- end;
- procedure TResTreeForm.RefreshTreeView(TreeView: TTreeView; Tree: TResTree);
- procedure TravelTree(Node: TNode; TreeNode: TTreeNode);
- var
- I: Integer;
- begin
- if Node = nil then Exit;
- TreeNode:= TreeView.Items.AddChild(TreeNode, Node.Text);
- TreeNode.Data:= Node;
- //CodeSite.SendString(PResInfo(Node.Data)^.FileName, '');
- for I:= 0 to Node.Count - 1 do
- TravelTree(Node.Children[I], TreeNode);
- end;
- var
- I: Integer;
- Node: TNode;
- begin
- TreeView.Items.Clear;
- Node:= Tree.RootNode;
- for I:= 0 to Node.Count - 1 do
- TravelTree(Node.Children[I], nil);
- end;
- procedure TResTreeForm.actLoadExecute(Sender: TObject);
- var
- szDir: string;
- begin
- if SelectDirectory('选择目录', 'E:', szDir) then
- begin
- FResTree.LoadFiles(szDir);
- RefreshTreeView(TreeView1, FResTree);
- end;
- end;
- procedure TResTreeForm.actDeleteUpdate(Sender: TObject);
- begin
- (Sender as TAction).Enabled:= TreeView1.Selected <> nil;
- end;
- procedure TResTreeForm.actDeleteExecute(Sender: TObject);
- begin
- FResTree.RemoveNode(TNode(TreeView1.Selected.Data));
- //TreeView1.Items.Delete(TreeView1.Selected);
- RefreshTreeView(TreeView1, FResTree);
- end;
- procedure TResTreeForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
- begin
- Label1.Caption:= IntToStr(FResTree.Count);
- end;
- procedure TResTreeForm.actRefreshExecute(Sender: TObject);
- begin
- RefreshTreeView(TreeView1, FResTree);
- end;
- end.