Module cCollection.pkg
1use VDFBase.pkg
2
3Register_Function IsObjectIn Handle ho Returns Integer
4
5{ HelpTopic=cCollection }
6Class cCollection is a Array
7 Procedure Construct_Object
8 Forward Send Construct_Object
9 { Category=Behavior }
10 Property Boolean pbAllowDuplicates False
11 End_Procedure
12
13 Procedure DoAppendObject Handle ho
14 If (pbAllowDuplicates(self) = False) Begin
15 If (IsObjectIn(self, ho)) Procedure_Return
16 End
17 Set Value (Item_Count(self)) To ho
18 End_Procedure
19
20 Procedure DoRemoveObject Handle ho
21 Integer iIndex
22 Get IndexFromObject ho To iIndex
23 If (iIndex <> -1) Send Delete_Item iIndex
24 End_Procedure
25
26 Procedure DoInsertObject Handle ho Handle hoBefore
27 Integer iIndex icObject iObject
28
29 If (pbAllowDuplicates(self) = False) Begin
30 If (IsObjectIn(self, ho)) Procedure_Return
31 End
32
33 Get IndexFromObject hoBefore To iIndex
34 If (iIndex <> -1) Begin
35 Get CountOfObjects To icObject
36 For iObject from 0 To (icObject -iIndex -1)
37 Set Value (icObject -iObject) To (Value(self, icObject -iObject -1))
38 Loop
39 Set Value iIndex To ho
40 End
41
42 End_Procedure
43
44 Function ObjectFromIndex Integer iIndex Returns Handle
45 // Returns the object-handle of the zero-based Button-index
46 Integer icObject
47 Handle hoObject
48
49 Get Item_Count To icObject
50
51 If (iIndex < icObject) Get Value iIndex To hoObject
52 Else Move 0 To hoObject
53
54 Function_Return hoObject
55 End_Function
56
57 Function IndexFromObject Handle ho Returns Integer
58 // Returns the index of the object, ho, in the collection
59 Integer iIndex iItem
60
61 For iIndex From 0 To (Item_Count(Self) -1)
62 If (Value(self, iIndex) = ho) Function_Return iIndex
63 Loop
64 Function_Return -1 // object not found
65 End_Function
66
67 Function CountOfObjects Returns Integer
68 Function_Return (Item_Count(self))
69 End_Function
70
71 Function IsObjectIn Handle ho Returns Boolean
72 // Is an object in the collection already?
73 Integer iIndex
74
75 Get IndexFromObject ho To iIndex
76
77 Function_Return (iIndex <> -1)
78 End_Function
79
80End_Class
81
82