Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do this in .NET
Message
De
15/04/2005 02:28:47
Walter Meester
HoogkarspelPays-Bas
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01004810
Message ID:
01004995
Vues:
32
Hi hugo,

>>
LPARAMETER oObject
>>LOCAL oX, nIndex, nT, lFound
>>
>>FOR nIndex= 1 TO oObject.CONTROLCOUNT
>>	oX=oObject.CONTROLS[nIndex]
>>
>>	DO CASE
>>		CASE oX.BASECLASS="Container"
>>			lFound=THISFORM.SetAddFocus(oX)
>>
>>		CASE oX.BASECLASS="Pageframe"
>>			FOR nT=1 TO oX.PAGECOUNT
>>				IF THISFORM.SetAddFocus(oX.pages(nT))
>>					oX.ActivePage=oX.Pages(nT).Pageorder
>>					lFound=.t.
>>				ENDIF
>>			ENDFOR
>>
>>		CASE PEMSTATUS(oX,"SetFocusAtAdd",5) AND oX.SetFocusAtAdd
>>			oX.Setfocus
>>			lFound=.T.
>>	ENDCASE
>>	IF lFound
>>		EXIT
>>	ENDIF
>>ENDFOR
>>RETURN lFound
>
>[Snipped]
>>This of course is not optimal as this code needs maintenance each time you use a new object type on your forms.
>>
>
>Walter,
>
>PMFJI, but, Aren't you having the same problem in here? In your CASE you ask for Container and PageFrame, that might change in the future if VFP adds a new "Container" class, and in fact it fails if the first parameter to oObject is a FormSet, right?

I don't think the problem is in the CASEs, but rather in the calling of the object as the compile would object since it cannot determine if it has a "SetFocusAtAdd" if the object type is specified at the object level. Therefore I have to cast it into the exact type. The problem here is that the number of object classes containing the property is essentially limitless and could grow during its development cycle. Of course the last thing you want is to maintain this piece of code whenever a new object type (class) is added.

And I agree since this code has been developped in VFP6 quite a few years ago, I would rewrite it into something more compact and general (using the objects collection) today.

>Why don't you do something like:
>
>
>* Method SetAddFocus
>LPARAMETER oRootObject
>LOCAL loObject, lFound
>
>if Pemstatus(oRootObject, 'Objects', 5)
>	for each loObject in oRootObject.Objects
>		if PEMSTATUS(loObject,"SetFocusAtAdd", 5) AND vartype(loObject.SetFocusAtAdd)='L' and loObject.SetFocusAtAdd
>			try
>				loObject.Setfocus()
>			catch
>				* Do something with error
>			endtry
>			lFound	=.T.
>		else
>			lFound	= Thisform.SetAddFocus(loObject)
>		ENDIF
>		IF lFound
>			EXIT
>		ENDIF
>	ENDFOR
>endif
>RETURN lFound
Yep this is one of the possibilities, however as I noted above the objects collection did not exist yet when I wrote the piece of code above.

Thanks.

Walter,
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform