Delphi代码 --> C++Builder代码 <font color=#FF0000>急!</font>(200分)

  • 主题发起人 主题发起人 prob
  • 开始时间 开始时间
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;
 
不敢多译,写一段吧,可能不对, 我不知道BCB里的类型是怎么定义样的
TTreeNode&amp;
function TreeFindItem(TTreeView&amp;
Sender;
TTreeNode&amp;
NodeItem;
String Name)
{
if (NodeItem == nil)
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))
do

NodeItem = NodeItem.getnextsibling;
while ((NodeItem != nil) and (NodeItem.text != Name));
return NodeItem;
}
 
to cheka:hehe
to prob:你的代码有几处地方有问题,我顺手改了一下,以下程序CB4中编译通过
//在TTreeview sender中查找text为name的节点
TTreeNode* TreeFindItem(TTreeView *Sender,TTreeNode *NodeItem,String Name)
{
if(NodeItem==NULL)
NodeItem=Sender->Items->GetFirstNode();
else
NodeItem=NodeItem->GetNext();
if((NodeItem!=NULL)&amp;&amp;(NodeItem->Text!=Name))
do
NodeItem=NodeItem->GetNext();
while((NodeItem!=NULL)&amp;&amp;(NodeItem->Text!=Name));
return NodeItem;
}
//在TTreeView Sender中增加一系列的节点,并排序
TTreeNode* TreeAddItem(TTreeView *Sender,TStrings* ItemsList,TBookmark *Bookmark,bool Resort)
{
TTreeNode *ThisNode,*Node;
int i;
Node=NULL;
for(i=0;i<ItemsList->Count-1;i++)
{
ThisNode=TreeFindItem(Sender,Node,ItemsList->Strings);
if(ThisNode!=NULL)Node=ThisNode;
else
{
if(i<ItemsList->Count-1)
{
if(i==0)Node=Sender->Items->Add(Node,ItemsList->Strings);
else
Node=Sender->Items->AddChild(Node,ItemsList->Strings);
}
else
{
if(i==0)Node=Sender->Items->AddObject(Node,ItemsList->Strings,Bookmark);
else
Node=Sender->Items->AddChildObject(Node,ItemsList->Strings,Bookmark);
}
Node->StateIndex=Node->Level+1;
if(Resort&amp;&amp;Node->Parent!=NULL)Node->Parent->AlphaSort();
}
}
return Node;
}
 
婪成这样,真是无话可说。
不过最简单的办法是把这几个函数放在一个unit中,
把函数公开,
在你在C++Builder程序中加入这个unit,
然后就可以直接使用这两个函数了。
 
不是懒啊,是CB语法都不懂,又没书,又急
 
好,不管了,你把分给我吧
 
TTreeNode * TForm1::TreeFindItem(TTreeView *Sender,TTreeNode *NodeItem,String Name)
{
if(NodeItem==NULL)
NodeItem=Sender->Items->GetFirstNode();
else
NodeItem=NodeItem->GetNext();
if((NodeItem!=NULL)&amp;&amp;(NodeItem->Text!=Name))
do
NodeItem=NodeItem->GetNext();
while((NodeItem!=NULL)&amp;&amp;(NodeItem->Text!=Name));
return NodeItem;
}
TTreeNode * TForm1::TreeAddItem(TTreeView * Sender , TStringList * ItemList ,void *Bookmark ,bool Resort )
{
TTreeNode *ThisNode, *Node;
int I;
Node = NULL;
for (I = 0 ;I<= ItemList->Count - 1 ;I++)
{
ThisNode = TreeFindItem(Sender, Node, ItemList->Strings);
if (ThisNode != NULL )
Node = ThisNode;
else
{
if ( I < ItemList->Count -1)
{
if (I == 0)
Node = Sender->Items->Add(Node, ItemList->Strings) ;
else
Node = Sender->Items->AddChild(Node, ItemList->Strings);
}
else
{
if (I == 0)
Node = Sender->Items->AddObject(Node, ItemList->Strings, Bookmark);
else
Node = Sender->Items->AddChildObject(Node, ItemList->Strings, Bookmark);
}
Node->StateIndex = Node->Level + 1;
if ((Resort)&amp;&amp;(Node->Parent != NULL ) )
Node->Parent->AlphaSort();
}
}
return Node;
}
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
688
SUNSTONE的Delphi笔记
S
S
回复
0
查看
683
SUNSTONE的Delphi笔记
S
后退
顶部