高效率从数据库提取数据,创建树形结构图

procedure BuildTree(TreeView: TTreeView; DataSet: TDataSet;
  KeyField, ParentField, TitleField: string);
{ 高效建树过程 by blazingfire 2008-05-21 }
type
  PNodeData = ^TNodeData;
  TNodeData = record
    Key: Integer;
    Parent: Integer;
    Title: string;
    Node: TTreeNode;
  end;

  function CompareKey(Item1, Item2: Pointer): Integer;
  begin
    Result := PNodeData(Item1)^.Key - PNodeData(Item2)^.Key;
  end;

  function BisearchNodeData(Key: Integer; SortedList: TList): PNodeData;
  var
    Lo, Hi, Mid: Integer;
  begin
    Lo := 0;
    Hi := SortedList.Count - 1;
    while Lo <= Hi do
    begin
      Mid := (Lo + Hi) div 2;
      Result := SortedList[Mid];
      if Key > Result^.Key then
        Lo := Mid + 1
      else if Key < Result^.Key then
        Hi := Mid - 1
      else<

你可能感兴趣的:(delphi笔记It's,long,long,ago,数据库,integer,list,dataset,function,string)