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:
01285937
Views:
19
Sorry, I should elaborate more.

I don't want developers using this class to be able to add items to the collection
from outside LoadInvoices.

Someone could do:
oCustomer.LoadInvoices()
oCustomer.oInvoices.lAllowLoad = .T.
oCustomer.oInvoices.Add(...)
See the problem?





>Would this work for you?
>
>DEFINE CLASS Col AS Collection
>  lAllowLoad = .T.
>  PROCEDURE Add(eItem, cKey, eBeforere, eAfter)
>    IF NOT This.lAllowLoad
>      ERROR 1740
>    ENDIF
>    ...
>  ENDPROC
>ENDDEFINE
>
>>
>>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.
>>
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