procedure LoadTree (treeDB: TDBDataSet); // initialize tree procedure UpdateTree (curNode: TTreenode; nodeTxt: string; state: string); // update the tree function GetNodeLevel (sFormat, sCode: string): integer; // get node layers Function GetNodeItem (Scode: String): Integer; // Get itm
{Public declarations} END;
Const ctreecodeformat = '122222'; ctreeMaxLevel = 6; ctreeroottxt = 'all books';
var tsgzlfrom: Ttsgzlfrom; _err: integer; curUser: string [10]; mystate: string; gNodeId: string; gNodelevel: integer; gNode: TtreeNode; mynode: array [0..6] of TTreenode; i, Already, CurMode: Integer; currow: integer; inIfile: string;
Level: integer;
IMPLEMENTATION
Uses bgnewunit;
{$ R * .dfm}
procedure TtsgzlFrom.LoadTree (treeDB: TDBDataSet); // initialize tree var curID, nodeTxt: string; level, num: integer; begin // initialize variables Screen.Cursor: = crHourGlass; tree.Enabled: = True; tree.Items. CLEAR; level: = 1; Num: = 1; Tree.Items.clear; // Set root node mynode [level]: = tree.Items.add (Tree.topITEM, CTREEROOTTXT); mynode [level] .ImageIndex: = 0; mynode [level] .selectedIndIndex: = 1; // Traverse the data table, use the coded field record rules, sequentially add the tree node with treen; first; while not Eof do beg, type: = = NOT EOF DO BEGIN CURID: = Trim (FieldByname ('tsglb'); nodetxt: = Curid '-' Trim (FieldByname ('tsglbn'). asstring); level: = getNodeEvel (CTREECODEFORMAT, CURID); // Return to code If Level> 0 THEN Begin // When the next node is added, the hierarchical relationship between the nodes can be easily implemented with the method of adding a child node. // Note: The parent of this is the last level of the current node MyNode [level-1] mynode [level]: = tree.Items.addchild (mynode [level-1], nodetxt); MyNode [level]. ImageIndex: = 2; MyNode [Level] .selectedIndIndex: = 3; end; next; // Next record end; finally; close; end; mynode [1] .expand (false); screen.cursor: = CRHOURGLASS; END; End; function ttsgzlfrom.GetNode: String: Integer; Var I, Ilen: Integer; Begin Level: = - 1; Ilen: = 0; IF (SFormat <> ') And (Scode <> " ') Then for i: = 1 to length (sformat) DO // Analysis Code format, find the current code hierarchy begin ilen: = Ilen StrtOINT (SFormat [i]); if longth (scode) = Ilen dam Level: = I; Break; end; end; result: = level;
Function TTSGZLFROM.GETNODEITEM (Scode: String): Integer; // Get Itemvar I, ICOUNT, VAL: Integer; TMP: String; Begin Result: = 0; ICOUNT: = Tree.Items.count; if Icount = 0. Val: = 0; for i: = 1 to ICOUNT-1 Do Begin TMP: = Tree.Items.Item [i] .text; tmp: = COPY (TMP, 0, POS (', TMP) -1) If TMP = Scode the Begin Val: = I; Break; End; End; Result: = Val; End; Procedure TTSGZLFROM.UPDATETREE (CURNODE: TTREENODE; NODETXT: STRING; StRING); begin if state = 'add' then begin curNode: = Tree.Items.addchild (curNode, nodeTxt); curNode.ImageIndex: = 2; curnode.SelectedIndex: = 3; end; if state = 'del' then curNode.delete; if state = 'edi' then Curnode.Text: = NODETXT;