P
prob
Unregistered / Unconfirmed
GUEST, unregistred user!
哪位大哥愿意把我下面的两个Delphi函数照葫芦画瓢改成C++Builder吗?越快越好!
function TreeFindItem(Sender: TTreeView;
NodeItem: TTreeNode;
Name: String): TTreeNode;
begin
if NodeItem = nil then
NodeItem := Sender.items.getfirstnode
else
NodeItem := NodeItem.getfirstchild;
//NodeItem is now the first item of the desired level
//if this level has no items, NodeItem is nil
if (NodeItem <> nil) and (NodeItem.text <> Name) then
repeat
NodeItem := NodeItem.getnextsibling;
until (NodeItem = nil) or (NodeItem.text = Name);
Result := NodeItem;
end;
function TreeAddItem(Sender: TTreeView;
ItemList: TStrings;
Bookmark: TBookmark;
Resort: Boolean): TTreeNode;
var
ThisNode, Node: TTreeNode;
I: Integer;
begin
Node := nil;
//nil = level 0 has no parent node
//this is checked by TreeFindItem
for I := 0 to Itemlist.count - 1do
begin
ThisNode := TreeFindItem(Sender, node, Itemlist);
if ThisNode <> nil then
Node := ThisNode else
begin
if I < Itemlist.count -1 then
begin
if I = 0 then
Node := Sender.items.Add(Node, Itemlist)
else
Node := Sender.items.AddChild(Node, Itemlist);
end else
begin
if I = 0 then
Node := Sender.items.AddObject(Node, Itemlist, Bookmark)
else
Node := Sender.items.AddChildObject(Node, Itemlist, Bookmark);
end;
Node.stateIndex := Node.level + 1;
if Resort and (Node.parent <> nil) then
Node.parent.alphasort;
end;
end;
Result := Node;
end;
function TreeFindItem(Sender: TTreeView;
NodeItem: TTreeNode;
Name: String): TTreeNode;
begin
if NodeItem = nil then
NodeItem := Sender.items.getfirstnode
else
NodeItem := NodeItem.getfirstchild;
//NodeItem is now the first item of the desired level
//if this level has no items, NodeItem is nil
if (NodeItem <> nil) and (NodeItem.text <> Name) then
repeat
NodeItem := NodeItem.getnextsibling;
until (NodeItem = nil) or (NodeItem.text = Name);
Result := NodeItem;
end;
function TreeAddItem(Sender: TTreeView;
ItemList: TStrings;
Bookmark: TBookmark;
Resort: Boolean): TTreeNode;
var
ThisNode, Node: TTreeNode;
I: Integer;
begin
Node := nil;
//nil = level 0 has no parent node
//this is checked by TreeFindItem
for I := 0 to Itemlist.count - 1do
begin
ThisNode := TreeFindItem(Sender, node, Itemlist);
if ThisNode <> nil then
Node := ThisNode else
begin
if I < Itemlist.count -1 then
begin
if I = 0 then
Node := Sender.items.Add(Node, Itemlist)
else
Node := Sender.items.AddChild(Node, Itemlist);
end else
begin
if I = 0 then
Node := Sender.items.AddObject(Node, Itemlist, Bookmark)
else
Node := Sender.items.AddChildObject(Node, Itemlist, Bookmark);
end;
Node.stateIndex := Node.level + 1;
if Resort and (Node.parent <> nil) then
Node.parent.alphasort;
end;
end;
Result := Node;
end;