treedemo.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:6k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit treedemo;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   fcTreeView, Buttons, StdCtrls, fcdbtreeview, ComCtrls,
  6.   shellapi, fcStatusBar, Db, DBTables, Grids, DBGrids, fcImager, fcCombo,
  7.   fcTreeCombo, fcFontCombo, fcDemoRichEdit, ImgList;
  8. type
  9.   TTreeViewDemoForm = class(TForm)
  10.     ImageList1: TImageList;
  11.     PageControl1: TPageControl;
  12.     TabSheet1: TTabSheet;
  13.     TabSheet2: TTabSheet;
  14.     fcTreeView1: TfcTreeView;
  15.     CheckBox1: TCheckBox;
  16.     CheckBox2: TCheckBox;
  17.     fcStatusBar1: TfcStatusBar;
  18.     fcTreeView2: TfcTreeView;
  19.     TabSheet3: TTabSheet;
  20.     fcTreeView3: TfcTreeView;
  21.     Label1: TLabel;
  22.     DataSource1: TDataSource;
  23.     Button1: TButton;
  24.     ImageList2: TImageList;
  25.     DBGrid1: TDBGrid;
  26.     fcDemoRichEdit1: TfcDemoRichEdit;
  27.     fcDemoRichEdit2: TfcDemoRichEdit;
  28.     Query1: TQuery;
  29.     fcDemoRichEdit3: TfcDemoRichEdit;
  30.     procedure CheckBox1Click(Sender: TObject);
  31.     procedure FormShow(Sender: TObject);
  32.     procedure CheckBox2Click(Sender: TObject);
  33.     procedure fcTreeView1CalcNodeAttributes(TreeView: TfcCustomTreeView;
  34.       Node: TfcTreeNode; State: TfcItemStates);
  35.     procedure fcTreeView2MouseMove(TreeView: TfcCustomTreeView;
  36.       Node: TfcTreeNode; Shift: TShiftState; X, Y: Integer);
  37.     procedure Table1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
  38.     procedure Button1Click(Sender: TObject);
  39.     procedure fcTreeView3ToggleCheckbox(TreeView: TfcCustomTreeView;
  40.       Node: TfcTreeNode);
  41.   private
  42.     { Private declarations }
  43.   public
  44.     { Public declarations }
  45.   end;
  46. var
  47.   TreeViewDemoForm: TTreeViewDemoForm;
  48. implementation
  49. {$R *.DFM}
  50. procedure TTreeViewDemoForm.CheckBox1Click(Sender: TObject);
  51. begin
  52.   with fcTreeView1 do begin
  53.      if tvoExpandButtons3D in Options then
  54.         Options:= Options - [tvoExpandButtons3D]
  55.      else Options:= Options + [tvoExpandButtons3D]
  56.   end
  57. end;
  58. procedure TTreeViewDemoForm.FormShow(Sender: TObject);
  59. begin
  60.    fctreeview1.FullExpand;
  61.    fctreeview2.FullExpand;
  62. end;
  63. procedure TTreeViewDemoForm.CheckBox2Click(Sender: TObject);
  64. begin
  65.   with fcTreeView1 do begin
  66.      if (Sender as TCheckBox).checked then
  67.         Options:= Options + [tvoRowSelect]
  68.      else
  69.         Options:= Options - [tvoRowSelect]
  70.   end
  71. end;
  72. procedure TTreeViewDemoForm.fcTreeView1CalcNodeAttributes(TreeView: TfcCustomTreeView;
  73.   Node: TfcTreeNode; State: TfcItemStates);
  74. begin
  75.     if fcisHot in State then TreeView.Canvas.Font.Style:= TreeView.Canvas.Font.Style + [fsUnderline];
  76. end;
  77. { Update statusbar to contain URL link address }
  78. procedure TTreeViewDemoForm.fcTreeView2MouseMove(TreeView: TfcCustomTreeView;
  79.   Node: TfcTreeNode; Shift: TShiftState; X, Y: Integer);
  80. begin
  81.    with TreeView do begin
  82.       if (Node<>Nil) and (Node.StringData<>'') and
  83.           (fchtOnItem in GetHitTestInfoAt(x,y)) then
  84.          fcStatusBar1.Panels[0].Text:= Node.StringData
  85.       else
  86.          fcStatusBar1.Panels[0].Text:= '';
  87.    end
  88. end;
  89. procedure TTreeViewDemoForm.Table1FilterRecord(DataSet: TDataSet;
  90.   var Accept: Boolean);
  91. var CurNode, ChildNode: TfcTreeNode;
  92.     CountryMatch, AmountOrderedMatch, AmountOwedMatch: boolean;
  93.     AmountOwed, AmountOrdered: Double;
  94. begin
  95.   { TreeView handle not available i.e. destroying}
  96.   if not fcTreeView3.HandleAllocated then exit;
  97.   accept:= False;
  98.   CountryMatch:= True;
  99.   AmountOrderedMatch:= True;
  100.   AmountOwedMatch:= True;
  101.   with fcTreeView3 do begin
  102.      curNode:= Items.GetFirstNode;
  103.      repeat
  104.         if (curNode.StringData = 'Country') and (curNode.checked) then begin
  105.            CountryMatch:= False;
  106.            { Search checkboxes for country to see if any countries match current record }
  107.            ChildNode:= curNode.GetFirstChild;
  108.            repeat
  109.               if ChildNode.checked then begin
  110.                  if dataset.fieldbyname('Country').asString = ChildNode.text then
  111.                  begin
  112.                     CountryMatch:= True;
  113.                     break;
  114.                  end;
  115.               end;
  116.               ChildNode:= ChildNode.GetNextSibling;
  117.            until ChildNode = nil;
  118.         end
  119.         else if (curNode.StringData = 'Amount Ordered') and (curNode.checked) then begin
  120.            { Check AmountOrdered to amount matches radio group selected in treeview }
  121.            AmountOrderedMatch:= False;
  122.            ChildNode:= curNode.GetFirstChild;
  123.            repeat
  124.               if ChildNode.checked then begin
  125.                  AmountOrdered:= dataset.fieldbyname('AmountOrdered').asFloat;
  126.                  with dataset.fieldbyname('AmountOrdered') do
  127.                     if ((ChildNode.StringData='') or
  128.                        (AmountOrdered >= strtoint(ChildNode.StringData))) and
  129.                        ((ChildNode.StringData2='') or
  130.                        (AmountOrdered < strtoint(ChildNode.StringData2))) then
  131.                     AmountOrderedMatch:= True;
  132.                  break;
  133.               end;
  134.               ChildNode:= ChildNode.GetNextSibling;
  135.            until ChildNode = nil;
  136.         end
  137.         else if (curNode.StringData = 'Amount Owed') and (curNode.checked) then begin
  138.            { Check AmountOrdered to amount matches radio group selected in treeview }
  139.            AmountOwedMatch:= False;
  140.            ChildNode:= curNode.GetFirstChild;
  141.            repeat
  142.               if ChildNode.checked then begin
  143.                  AmountOwed:= dataset.fieldbyname('AmountOrdered').asFloat -
  144.                               dataset.fieldbyname('AmountPaid').asFloat;
  145.                  if ((ChildNode.StringData='') or
  146.                     (AmountOwed > strtoint(ChildNode.StringData))) and
  147.                     ((ChildNode.StringData2='') or
  148.                     (AmountOwed <= strtoint(ChildNode.StringData2))) then
  149.                     AmountOwedMatch:= True;
  150.                  break;
  151.               end;
  152.               ChildNode:= ChildNode.GetNextSibling;
  153.            until ChildNode = nil;
  154.         end;
  155.         curNode:= curNode.GetNextSibling;
  156.      until curNode=nil;
  157.   end;
  158.   if CountryMatch and AmountOrderedMatch and AmountOwedMatch then accept:= true;
  159. end;
  160. procedure TTreeViewDemoForm.Button1Click(Sender: TObject);
  161. begin
  162.    { Reapply filter by refreshing query locally }
  163.    query1.updatecursorpos;
  164.    query1.resync([rmCenter]);
  165. end;
  166. procedure TTreeViewDemoForm.fcTreeView3ToggleCheckbox(
  167.   TreeView: TfcCustomTreeView; Node: TfcTreeNode);
  168. begin
  169.    if (Node.Level=1) and (Node.checked) then
  170.       Node.parent.checked:= True;
  171. end;
  172. end.
  173.