Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OCollection_ASSIGN Problem
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01219959
Message ID:
01285918
Views:
14
Sergey,

I want to follow up on this:
PROCEDURE LoadInvoices

This.oInvoices = CREATEOBJECT("Col")

SELECT *;
	FROM Invoices;
	WHERE CustomerId = iCustomerId;
	INTO CURSOR Temp1

SELECT Temp1
SCAN

	oInvoice = CREATEOBJECT("Invoice", Temp1.InvoiceId)
	
	** Add the invoice object to the collection
	This.oInvoices.Add(oInvoice)

ENDSCAN

RETURN


DEFINE CLASS Col AS Collection
	PROCEDURE Add(eItem, cKey, eBeforere, eAfter)
	ENDPROC
ENDDEFINE
The question is how do I make the collection property read-only AFTER I have loaded it.

I considered defining a public variable "goAllowLoad" in the LoadInvoices and then check
to see of it's defined in the Add method of the collection, and if not, throw error 1740
("name" is a read-only property), but this seems ugly to me.

Any ideas?



>The _Assign method only fires when property is changed. Adding items to collection doesn't change its reference stored in the property .oTabs. You can create a subclass of Collection with overriten Add method.
>
>CLEAR
>o =  CREATEOBJECT("MyCollection")
>= o.Add("Apple")
>= o.Add("Orange")
>= o.Add("Banana",,2)
>? o.Item(1)
>? o.Item(2)
>? o.Item(3)
>RETURN
>
>DEFINE CLASS mycollection as Collection
>	FUNCTION Add(eItem, cKey, eBeforere, eAfter)
>		? "Added " + eItem
>	ENDFUNC
>ENDDEFINE
>
>
>>I want to trap when the code adds an object to a collection.
>>
>>I have a property, 'oTab's, which has an assign method. In the Init I have:
>>
>>
>>.oTabs = CREATEOBJECT("Collection")
>>
>>
>>The _Assign method only fires when this line of code fires, not when
>>items are added to the collection.
>>
>>Any way to do this?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform