Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Recursion, how best to code ?
Message
De
24/01/2001 13:21:49
 
 
À
24/01/2001 11:33:30
Tan Aik Jin
Aranea WebLab Sdn Bhd
Kuala Lumpur, Malaisie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00467922
Message ID:
00468047
Vues:
23
Tan:

If I understand your post correctly, you want to automatically
add all linked items. For example, if the user selects C2, you
want to add items A3, C1, A1 and all items linked to A3.

If this assumption is correct, you can use a recursive function
similar to this one (untested pseudo-code):
Local lcItemID              && The ID of the item for which you
                            && want to retrieve all the linked
                            && items.
Local laLinkedItems[1]      && Store the ID of the linked items.
Local lnLinkedItemCount     && The number of items linked.

lcItemID = < some item ID >
raLinkedItems[1] = ''

lnLinkedItemCount = RetrieveLinkedItems(@laLinkedItems, lcItemID)

....

Function RetrieveLinkedItems
Lparameters raLinkedItems, tcItemsID, tlInitialized

Local lnRetVal 

If Not tlInitialized Then
   Dimension raLinkedItems[1]
   raLinkedItems[1] = ''
EndIf

lnRetVal = 0
If tcItemID is present in your table
   Locate tcItemID in your table
   
   For Each Item lcLinkedID In PointsTo
      If lcItemID is not already present in array Then
         If Empty(raLinkedItems[1]) Then
            raLinkedItems[1] = lcLinkedID
         Else
            Dimension raLinkedItems[ALEN(raLinkedItems) + 1]
            raLinkedItems[ALEN(raLinkedItems)] = lcLinkedID
         EndIf
         
         =RetrieveLinkedItems(@raLinkedItems, lcLinkedID, .T.)
      EndIf
   EndFor
EndIf

If Not tlInitialized Then
   lnRetVal = Iif(Empty(raLinkedItems[1]), 0, Alen(raLinkedItems))
Else
   *-- To denote it is a recursive call (you could return the 
   *-- number of items added as an alternative)
   lnRetVal = -1
EndIf


Return ( lnRetVal )
Daniel
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform