这是DBtrees控件
unit DBTrees;
interface
uses ComCtrls, DB;
type
TTreeNodeInfo=record
Id:String;
ParentId:String;
end;
TDBTreeView=class(TTreeView)
private
fTable:TDataSet;
fId,fParentId,fName:string;
function AddItem:TTreeNode;
function FindItem(Id:string):TTreeNode;
public
function GetId:string;
procedure BuildTree;
procedure ClearTree;
published
property FieldId:string Read fId Write fId;
property FieldParentId:string Read fParentId Write fParentId;
property FieldName:string Read fName Write fName;
property DataSource:TDataSet Read fTable Write fTable;
property ActiveId:string Read GetId;
end;
procedure Register;
implementation
function TDBTreeView.FindItem(Id:string):TTreeNode;
var i:integer;
NodeInfo:^TTreeNodeInfo;
begin
Result:=nil;
For i:=0 to Items.Count-1 do
begin
NodeInfo:=Items.Data;
If NodeInfo^.Id=Id then
begin
Result:=Items;
Exit;
end;
end;
end;
function TDBTreeView.GetId:string;
var NodeInfo:^TTreeNodeInfo;
begin
If Selected=nil then Result:=''
else
begin
NodeInfo:=Selected.Data;
Result:=NodeInfo^.Id;
end;
end;
function TDBTreeView.AddItem:TTreeNode;
var NodeInfo:^TTreeNodeInfo;
BMark:TBookMark;
ObjParent:TTreeNode;
Name,CurId:string;
begin
ObjParent:=FindItem(fTable.FieldByName(fId).AsString);
If ObjParent<>nil then
{钺?牝 箧?漕徉怆屙 ?溴疱忸}
begin
Result:=ObjParent;
Exit;
end
else
{漕徉怆