Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do this in .NET
Message
 
À
14/04/2005 14:01:41
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01004810
Message ID:
01004831
Vues:
31
Not sure if this applies to your question, but I believe the way that the Mere Mortals .NET framework handles this is:

1. The form has a FocusOnNewControl property, which is of type Control. I believe all windows controls are derived from this class.
1. The form itself calls a business object to add a new record, typically after a button is clicked.
2. After the business object (called a primary business object) has created the record, if the FocusOnNewControl is not null, the form calls the control's Focus() method.

Not sure if I explained that very well, but I think that is the gist of it.


>started from a discussion at Re: VFPConversion Seminar - May 9-10 - Dallas, TX Thread #1002513 Message #1004659
>
>The question is for both VB.NET and C#
>
>In my VFP framework, when I add a record, the framework searches the activeform for objects who have a "SetFocusAtAdd" property and have this property set as .T. This object will receive focus as soon as a record has been added. The object in question can be a textbox, checkbox, commandbutton, combox, listbox or any subclass of that whatsoever. The Implementation of the algortihm is simular to the one beneath. When calling the routine, generally the object contains THISFORM in the first call.
>
>
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
>
>The problem here is that .NET is static typed and the compiler wants to know the type of the object beeing passed. Now I do understand that if you define the parameter oObject as type object the passing of the parameter is not a problem since all visual classes inherit from this class.
>
>Where it becomes tricky is that when you want to check if a property SetFocusAtAdd exists and it is set. The passed object might or might not have such propery and the compiler insist on knowing the type of the object before you check any propery non existing on the object class.
>
>RodPaddock came up with a solution like the following on order to make a typecast:
>
>
If TypeOf oObject is IRodBinding
>Ctype(oObject,IRodBinding).BindingFunction
>Else......
>
>
>The problem with this approach is that it is not really an OO solution (in fact I've been burned for that at university when doing this when implementing a scalar math language inC++) as the OO language should provide a mechanism to make this unneccesary. The other problem with this is that a form can contain many different objecttypes which might or not might have the "SetFocusAtAdd" property. Implementing it this way would require a If TypeOf construct for each imaginary class on the form which contains the required property. This of course is not optimal as this code needs maintenance each time you use a new object type on your forms.
>
>I remember from programming C++ (I admit a long time ago) you can solve simular problems with virtual functions, but they only work if the virtual function exists on the parent class declared as a parameter in the same function. In this case any subclass of the oObject parameter might have or not have this property.
>
>The question is then. How to solve this in a strict typed language like .NET in the most optimal way?
>
>Thanks,
>
>Walter,
Chris McCandless
Red Sky Software
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform