Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do this in .NET
Message
De
15/04/2005 06:01:24
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
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:
01005029
Vues:
26
>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,

Walter,
If you wouldn't ask for the code now (I believe I posted it partially before here) I did that using System.Reflection. However you ask for the optimal way:) In .Net there are too many classes and too many ways to reach to same endpoint so I'm not sure what I did was the optimal one or not. But also think of this:
In .net you can get an xml representation of an object if it's serializable and might quickly process xml to find what you want - just another way.
Up till now I couldn't find anything that I can do in VFP but not in .Net (it only takes more time in .Net but that's specific to my relatively much more little knowledge with .Net than it is with VFP).
PS: I used GetType() and Type class members like MemberInfo, FieldInfo, PropertyInfo etc instead of typeof() so I needn't know the type beforehand and create a switch for every possible new object. It looks like amembers() processing in VFP. Off topic I hate in VFP I need Pages/PageCount, Buttons/ButtonCount etc (yes there are Objects but still I hate:)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform