内存里面的数组pid_node_array我已经;用工具看过了 数据没错
但是如果num=任何值的时候都只循环2次 而且 if pid_node_array[i].pid=parentid then 这句也有问题,相等的时候也不会进入begin,可能跟循环有关系可能有个特别简单的问题在里面 我看了半天没找到
function TForm1.getPNode(parentid:Integer;num:Integer):TTreeNode;
var
i:Integer;
begin
for i:=0 to num-1 do
begin
if pid_node_array[i].pid=parentid then
begin
result:=pid_node_array[i].node;
break;
end;
end;
result:=pid_node_array[0].node;
end;
但是如果num=任何值的时候都只循环2次 而且 if pid_node_array[i].pid=parentid then 这句也有问题,相等的时候也不会进入begin,可能跟循环有关系可能有个特别简单的问题在里面 我看了半天没找到
function TForm1.getPNode(parentid:Integer;num:Integer):TTreeNode;
var
i:Integer;
begin
for i:=0 to num-1 do
begin
if pid_node_array[i].pid=parentid then
begin
result:=pid_node_array[i].node;
break;
end;
end;
result:=pid_node_array[0].node;
end;
1。你这函数逻辑上就有问题。不管里面条件如何,最后的结果都是:result:=pid_node_array[0].node;
result:=pid_node_array[0].node;这句应该放在For循环里面。就这问题,你可以直接把Break改为Exit。2。一个函数输出一个节点,个人觉得不妥,呵呵。你可以把要输出的值做为函数的一个参数来操作。输出结果可以是Boolean的值。就像API函数一样。3。For循环中估计可能也有问题,没调试,不敢乱说。呵呵。。