yikes! still clear as mud.
since the array wasnt being resized i thought that the assignment must 
be a mixup. i didnt get the purpose of the function. i thought nodes was 
already loaded..

but cant we just measure the array before resizing and adding the new 
node? i still dont get we need an external counter. at any time the 
array is "full", and just needs to be measured and extended by one. 
still dont need to save or pass the size globally..it already implicit 
in the var paramater nodes array.

also, isn't it ugly (though not illegal) to assign a value to a 
parameter inside the function? or is this necessary for type compatability?


PObjArray = array of tsxGNODE;

procedure tsGrpExtractNodes(grp: tsxGROUP; var nodes: PObjArray);
var
  pChildNode: tsxSOBJ;
  objtype: tsxSOBJTYPE;
begin
  pChildNode:= tsxGNodeGetFirstChild(grp);
  while (pChildNode <> nil) do begin
    objtype:= tsxSobjGetType(pChildNode);
    if ((objtype = e_tsxGROUP) or (objtype = e_tsxIKGROUP)) then begin
      grp:= pChildNode;//lets not do this, just put pChildNode right into the 
recursive call
      tsGrpExtractNodes(pChildNode, nodes);
    end
    else begin
      //adding to array
      SetLength(nodes,Length(nodes)+1);
      nodes[Length(nodes)-1]:= pChildNode;
    end;
    pChildNode:= tsxGNodeGetNext(pChildNode);
  end;
end;

and i dont get why you resized the array AFTER the recursive call in 
your nested-function approach.. isnt it too late then?

   Count := 0;
   ExtractNodesWorker(grp, nodes, Count);
   SetLength(nodes, Count);

thanks for helping me understand this Robert, if im being tedious just 
say so.


[EMAIL PROTECTED] wrote:

>Dan Kloke wrote:
>  
>
>>i dont get why theres an assignment to the nodes array in the middle of 
>>this, so maybe i dont get what youre doing here. it looks like the 
>>nodes:PObjArray array is being changed by the counting process.. that 
>>cant be a good idea.
>>    
>>
>
>But that's the entire purpose of the function. It scans the tree and 
>accumulates all the matching nodes into the array -- hence the name of 
>the function, ExtractNodes. The Count value is used not only to count 
>how many items there are, but also to denote the next empty spot in the 
>array, so the function knows where to store the next matching node. Thus 
>the count can't simply be a function return value since it also needs to 
>be an input parameter indicating how full the array already is.
>
>  
>
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to