Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# version of VFP PEMSTATUS()
Message
De
19/01/2010 10:29:33
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01444636
Message ID:
01444748
Vues:
45
>>>>>>>
>>>>>>>As to why method has to belong to a form. I don't know (can't see) where else this method would belong. That is, I add/create a method in the form that enabled/disables certain buttons. At run time the code in each text box event OnTextChange needs to "know" if this (parent) form class has this method or not. So in the OnTextChanged method I need to determine (at run time) if the form class has this method.
>>>>>>
>>>>>>
>>>>>>Dmitry,
>>>>>>
>>>>>>I'm not in a position to give expert advise - but let me give a thought
>>>>>>
>>>>>>I do not think the GetPemstatus is the .net way - it belongs to the IDE in development mode
>>>>>>
>>>>>>Are your forms based on a common (sub) class. If so, you can add a method to the subclass that does nothing. Each textbox can call the method
>>>>>>If you need some code in it why not override that method in the forms that need it ?
>>>>>>
>>>>>>You can make that more explicit by defining an interface and have your common sub class implement that interface. All the forms can override the method
>>>>>>
>>>>>>Depending on what you want to do, you can even add an eventhandler to the form, or add a class/object to the form that is reponsible for that behaviour
>>>>>>
>>>>>>The textbox' OnTextChange event can forward that event to that class/object you have added to the common subclass form.
>>>>>
>>>>>Gregory,
>>>>>
>>>>>Thank you very much for your input. And I also thought about the approach you bring up: creating a base class of a form with a method that I need. All that you say makes sense. Many choices.
>>>>
>>>>I hope Viv/Bonnie will chime in - they will give you more professional advice
>>>>I would go for the last option (add a class/object to the form that is reponsible for that behaviour), although I cannot give you practical advice on that
>>>>If I look at my form's base class in foxpro - I see it has loads of methods, that have got in gradually over the years - sometimes it's difficult to get the picture back
>>>>I'm in favour of a 'specialized' class - which you can add to the form - for the thing you are after
>>>
>>>Right now my forms are based on the default Form class. I think it would be nice to create "my own" Form class (based on the Form class) and then use it in my forms. But I am a little concerned about messing up something and causing the entire thing to break down. On one hand I am making baby steps in learning and building this program at the same time keeping in mind the delivery date getting closer and closer (do you know how to spell "living under pressure"?<g>).
>>>
>>>Thank you. I will think about these things.
>>
>>If the code in the Form.MyMethod() is always (or even usually) the same it could make sense to sub-class the form so as to avoid having the add the code in every form that implements the method. But it might make sense to use an interface as well to simplify the referencing problems. Something like:
public interface IMyInterface
>>{
>>    void MyMethod(bool b);
>>}
>>
>>public class MyForm : Form, IMyInterface
>>{
>>    public void MyMethod(bool b)
>>    {
>>    }
>>}
>>
>>public class MyTextBox : TextBox
>>{
>>    protected override void OnTextChanged(EventArgs e)
>>    {
>>        if (this.Parent is IMyInterface)
>>        {
>>            ((IMyInterface)this.Parent).MyMethod(true);
>>        }
>>        base.OnTextChanged(e);
>>    }
>>}
The assemblies containing the Form and the TextBox would both need references to the assembly where the interface is defined. Mark the MyMethod() as virtual if you might need to vary the behavior.
>
>Viv, again thank you for the code. In my case the code in MyMethod will be a little different for each form. So using Interface should do the job. The only thing that still kind of a question in my mind is what is faster:
>
>a) using Interface-type method and checking for method using the code above
>b) simply adding a method to the form class and checking for existence of the method using PEMStatus() (.NET version) code using Reflection.

a will be faster. (and less error-prone - too easy when using reflection to mis-type property names etc.....)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform