Re: [fpc-pascal] TreeView and Nonrecursion
On September 2, 2010 5:14:50 PM, Juha Manninen wrote: > If your input data contains a string which always > identifies the parent node then you can map the > string -> "parent node" and find it later for adding > a child node. > > Pseudo code again: > ... > ... > If you don't have such ID then you must use recursion. Thanks José and Juha, now I see the light. :-) On September 2, 2010 8:11:53 PM, Flávio Etrusco wrote: > When reading from registry and populating a treeview, a > recursive function is the least of your worries regarding > "performance" (or memory, if you're careful). I'm a crash-phobia :-). Stack sizes are different among the OS platforms. A superdeep recursion will trigger a stack overflow exception. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TreeView and Nonrecursion
On Wed, Sep 1, 2010 at 6:20 PM, Bihar Anwar wrote: > On 2 September 2010 3:53:34 AM, Vannus wrote: > >> i probably shouldn't open my mouth, as i don't quite understand the >> question... >> however FRED from the game Freespace let you design missions using a >> treeview. > > Just to make my question clear, for example, I can fill a TreeView control > with particular Registry keys by enumerating registry keys recursively and > put them in the TreeView control; then for performance reason, I attempt to > use a nonrecursive/iterative approach to enumerate registry keys, but how > can I fill the TreeView since a "tree" is naturally recursive? Is recursion > is the only way to achive it? > When reading from registry and populating a treeview, a recursive function is the least of your worries regarding "performance" (or memory, if you're careful). -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TreeView and Nonrecursion
On Thursday 02 September 2010 00:47:23 José Mejuto wrote: > You must know at which node a new node must be inserted... If your input data contains a string which always identifies the parent node then you can map the string -> "parent node" and find it later for adding a child node. Pseudo code again: var ParentNode, Node: TNode; Map: TStringHashMap; ParentId, Id: string; ... // get data from somewhere ParentId := ... Id := ... ParentNode := Map[ParentId]; // This should make Node a root node if ParentNode = nil. Node := Tree.AddNode(ParentNode, Id); // Pseudo syntax. Map[Id] := Node; // Use as parent for following nodes. If you don't have such ID then you must use recursion. Juha ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re[2]: [fpc-pascal] TreeView and Nonrecursion
Hello FPC-Pascal, Wednesday, September 1, 2010, 11:20:57 PM, you wrote: BA> Just to make my question clear, for example, I can fill a TreeView control with BA> particular Registry keys by enumerating registry keys recursively and put them BA> in the TreeView control; then for performance reason, I attempt to use a BA> nonrecursive/iterative approach to enumerate registry keys, but how can I fill BA> the TreeView since a "tree" is naturally recursive? Is recursion is the only way BA> to achive it? You must know at which node a new node must be inserted, but you can write something like (pseudo code): procedure FillConditional(var ParentNode: TNode); var j: integer; l: TList; n: TNode; begin l:=TList.Create; n:=nil; for j:=0 to do begin //xxx is some kind of condition n:=TNode.Create; n.position:=j; Tree.AddNode(ParentNode,n); if j=10 then begin l.add(n); //Remember the node at position 10 end; end; for j:=0 to n.Count-1 do begin n:=l.Items[j]; FillConditional(n); end; l.free; end; It is recursive, but first you add all sibliings and them you add each new brach linearly. -- Best regards, José ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TreeView and Nonrecursion
On 2 September 2010 3:53:34 AM, Vannus wrote: > i probably shouldn't open my mouth, as i don't quite understand the >question... > > however FRED from the game Freespace let you design missions using a treeview. Just to make my question clear, for example, I can fill a TreeView control with particular Registry keys by enumerating registry keys recursively and put them in the TreeView control; then for performance reason, I attempt to use a nonrecursive/iterative approach to enumerate registry keys, but how can I fill the TreeView since a "tree" is naturally recursive? Is recursion is the only way to achive it? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TreeView and Nonrecursion
i probably shouldn't open my mouth, as i don't quite understand the question... however FRED from the game Freespace let you design missions using a treeview. It involved following a tree like |- when 'Enemy Cargo ship' is 'attacked' | \- then 'enemy support ships' do 'jump in' |- when 'Enemy Cargo ship' is 'destroyed' | \- then 'mission successful' |- etc... or do you mean the other way around where the thinking paradigm fills in the treeview? - V On 1 September 2010 21:40, Bihar Anwar wrote: > A Newbie question :-) Is it possible to fill TreeView (tree is naturally > recursive) with a nonrecursive/iterative thinking paradigm? Are there some > good > examples regarding this matter in the Internet? > > I post this question in FPC mailing list because my question actually about > filling a "tree" in general. > > Thanks in advance. > > > > > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] TreeView and Nonrecursion
A Newbie question :-) Is it possible to fill TreeView (tree is naturally recursive) with a nonrecursive/iterative thinking paradigm? Are there some good examples regarding this matter in the Internet? I post this question in FPC mailing list because my question actually about filling a "tree" in general. Thanks in advance. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal