Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Working with the collection class
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01017111
Message ID:
01017151
Views:
25
Chad,

Good questions.

I add objects (containers to be presize) into my collection. I use NamedSearch as the key and this I can not change, because I use it in many places.

Now, how may I ensure, that my colleaction has containers added in the order of their TabOrder? I want to avoid iterating through collection if I may add my containers the right way in the beginning.

Here is a trick I use to add objects to the collection:
I have a property of the container called lRegister with the assign method. In that method I do:
*---------------------- Location Section ------------------------
*   Library: 	Asearchcontrols.vcx
*   Class: 		Cntsearchparent  
*   Method: 	Lregister_assign() 
*----------------------- Usage Section --------------------------
*)  Description: 
*)

*   Scope:      Public
*   Parameters: 
*$  Usage:      
*$              
*   Returns:  
*--------------------- Maintenance Section ----------------------
*   Change Log:
*       CREATED 	05/20/2005 - NN 
*		MODIFIED
*----------------------------------------------------------------
LPARAMETERS vNewVal
*To do: Modify this routine for the Assign method
THIS.lRegister = m.vNewVal
IF this.lRegister 
   thisform.RegisterControls(this.class, SUBSTR(this.Name,2))
endif
In the Init of the form I call thisform.SetAll('lRegister',.t.).

My containers are named:
oCLIENTACCOUNT
oPATIENTSSN
oMEDICAIDNUMBER
etc.

The part after o is used for the search. E.g I build the whole search logic using this part and I did it in DO CASE statement, like this:
*---------------------- Location Section ------------------------
*   Library: 	Asearchbiz.vcx
*   Class: 		Searchobject
*   Method: 	GetWhereExpr()
*----------------------- Usage Section --------------------------
*)  Description:
*)

*   Scope:      Public
*   Parameters:
*$  Usage:
*$
*   Returns:
*--------------------- Maintenance Section ----------------------
*   Change Log:
*       CREATED 	05/15/2005 - NN
*		MODIFIED
*----------------------------------------------------------------
lparameters tcSearchType, taFieldsVals
external array taFieldsVals
local lcSearchType, lnI, llReturn
lcSearchType = lower(m.tcSearchType)

#define ADDWHERE iif(empty(this.cWhereExpr),"", this.cWhereExpr + " AND ")
#define ADDJOIN iif(empty(this.cJoinExpr),"", this.cJoinExpr + " ")
#define GuarantorPrefix iif("guarantor" $ m.lcSearchType, "Guarantor_", "")
#define dDOBField iif("guarantor" $ m.lcSearchType, "Relateds.dDOB", "Patients.dDOB")

llReturn = .t.

if m.llReturn
	do case

* Name
	case "name" $ m.lcSearchType
		for lnI = 1 to alen(taFieldsVals,1)
			if lower(taFieldsVals[m.lnI,1]) = "lastname"
				this.cWhereExpr = ADDWHERE + GuarantorPrefix + [Names.] + [cl_name LIKE "] + ;
					alltrim(taFieldsVals[m.lnI,2]) + [%"]
			endif
			if lower(taFieldsVals[m.lnI,1]) = "firstname"
				this.cWhereExpr = ADDWHERE + GuarantorPrefix + [Names.] + [cf_name LIKE "] + ;
					alltrim(taFieldsVals[m.lnI,2]) + [%"]
			endif
			if lower(taFieldsVals[m.lnI,1]) = "middleinitial"
				this.cWhereExpr = ADDWHERE + GuarantorPrefix + [Names.] + [cm_initial LIKE "] + ;
					alltrim(taFieldsVals[m.lnI,2]) + [%"]
			endif
		next

		this.cWhereExpr = ADDWHERE + GuarantorPrefix + [Names.] + [iAlias_Flag <> 1 ]

		if "guarantor" $ m.lcSearchType
			this.cWhereExpr = ADDWHERE + GuarantorPrefix + "Names.cPointer_Table_Name = 'RELATEDS'"

			if not " trans_relateds" $ lower(this.cJoinExpr     )
				this.cJoinExpr = ADDJOIN + "INNER Join Trans_Relateds on Trans.cTrans_pk = Trans_Relateds.cTrans_fk"
			endif

			if not GuarantorPrefix + "Names" $ this.cJoinExpr
				this.cJoinExpr = ADDJOIN + "INNER Join Names " + ;
					GuarantorPrefix + ;
					"Names on Trans_Relateds.cRelateds_fk = " + ;
					GuarantorPrefix + ;
					"Names.cPointer_fk"
			endif
		else
			this.cWhereExpr = ADDWHERE + "Names.cPointer_Table_Name = 'PATIENTS'"
		endif

* Client Account Number
	case m.lcSearchType = [hospitalacctnum]
		this.cWhereExpr = ADDWHERE + [Trans.cClient_account_number LIKE "] + alltrim(taFieldsVals[1,2]) + [%"]

* Patient's SSN
	case "patientssn" $ m.lcSearchType
		this.cWhereExpr = ADDWHERE + [Patients.cSSN LIKE "] + alltrim(taFieldsVals[1,2]) + [%"]

* Phone
	case inlist(m.lcSearchType, "patientphone","guarantorphone" )
		for lnI = 1 to alen(taFieldsVals,1)
			if lower(taFieldsVals[m.lnI,1]) = "areacode"
				this.cWhereExpr = ADDWHERE + GuarantorPrefix + ;
					[Phones.] + [cArea_Code LIKE "] + ;
					alltrim(taFieldsVals[m.lnI,2]) + [%"]
			endif
			if lower(taFieldsVals[m.lnI,1]) = "exchange"
				this.cWhereExpr = ADDWHERE + GuarantorPrefix + ;
					[Phones.] + [cExchange LIKE "] + ;
					alltrim(taFieldsVals[m.lnI,2]) + [%"]
			endif
			if lower(taFieldsVals[m.lnI,1]) = "lastfour"
				this.cWhereExpr = ADDWHERE + GuarantorPrefix + ;
					[Phones.] + [cLast_four LIKE "] + ;
					alltrim(taFieldsVals[m.lnI,2]) + [%"]
			endif
			if lower(taFieldsVals[m.lnI,1]) = "extension"
				this.cWhereExpr = ADDWHERE + GuarantorPrefix + ;
					[Phones.] + [cExtension LIKE "] + ;
					alltrim(taFieldsVals[m.lnI,2]) + [%"]
			endif
		next

		if "guarantor" $ m.lcSearchType
			this.cWhereExpr = ADDWHERE + GuarantorPrefix + ;
				"Phones.cPointer_Table_Name = 'RELATEDS'"

			if not "trans_relateds" $ lower(this.cJoinExpr)
				this.cJoinExpr = ADDJOIN + "INNER Join Trans_Relateds on Trans.cTrans_pk = Trans_Relateds.cTrans_fk"
			endif

			if not GuarantorPrefix + "Phones" $ this.cJoinExpr
				this.cJoinExpr = ADDJOIN + "INNER Join Phones " + ;
					GuarantorPrefix + ;
					"Phones on Trans_Relateds.cRelateds_fk = " + ;
					GuarantorPrefix + ;
					"Phones.cPointer_fk"
			endif
		else
			if not " Phones" $ this.cJoinExpr
				this.cJoinExpr = ADDJOIN + "INNER Join Phones " + ;
					"on Patients.cPatients_pk = Phones.cPointer_fk"
			endif
			this.cWhereExpr = ADDWHERE + "Phones.cPointer_Table_Name = 'PATIENTS'"
		endif
etc.

>Nadya,
>
>Are you adding object references to the collection? Or the name that can be EVALUATED() to reference the control? You have a few different options depending on what and how you are storing the data. I'm not real clear on what you are trying to achieve. One option would be to use something like tN (where t is a prefix letter and N is the TabOrder) as the cKey and then set the KeySort property of your collection to 2 (Key ascending). Then, when you iterate through the collection it would be in TabOrder. Another option, if you are storing actual object references would be to have a sort method that iterated through the collection, stored the object reference, search name, and TabOrder (read from the object reference) and then sort the array (with ASORT()). Then, you could clear the collection and reload it in the proper order or just return the objects as a sorted array. There are probably other options as well. It really just depends on exactly what you are needing.
>
>Can you provide more details?
>
>HTH,
>Chad
>
>>Hi everybody,
>>
>>I'm not sure, how can I add items to the collection based on their TabOrder in the form.
>>
>>Here is my current code, I'd like to modify it to put controls in the TabOrder sequence. How should I do it?
>>
>>
>>*---------------------- Location Section ------------------------
>>*   Library: 	Aformssearch.vcx
>>*   Class: 		Frmquicksearch
>>*   Method: 	Registercontrols()
>>*----------------------- Usage Section --------------------------
>>*)  Description:
>>*)
>>
>>*   Scope:      Public
>>*   Parameters:
>>*$  Usage:
>>*$
>>*   Returns:
>>*--------------------- Maintenance Section ----------------------
>>*   Change Log:
>>*       CREATED 	05/20/2005 - NN
>>*		MODIFIED
>>*----------------------------------------------------------------
>>lparameters tcClassName, tcNamedSearch
>>
>>with thisform.oSearchCollection
>>	if .getkey(m.tcNamedSearch) = 0
>>		.add(m.tcClassName, m.tcNamedSearch)
>>	endif	
>>endwith
>>
>>
>>
>>My container object has a name of "o" + m.tcNamedSearch and it's placed directly on the form.
>>
>>Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform