Re: Using form controls from other classes.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Potential problems include...
1. Form's constructor creates A, whose constructor in turn creates C.
As mentioned in my additional information #2, I want to disable a
button on Form when C catches the exception. It won't use my exception
handler because I add the handler after creating the objects. To solve
the problem, I moved A and C's constructors into initialization
methods and subscribed before calling the initialization method. I
feel like there would be a better solution. I can't really complain
though. It works and didn't require exposing my forms elements. Maybe
given the recent additional information I have provided below, you
might suggest a different approach.
2. My Form contains the handlers for all events including logging. To
log from within the Form itself, I've just been calling my handler.
I'm not really sure if that is the proper way, but it works.

I figured I would add a bit more information since I'm still stuck
trying to figure out the best way to approach this. I have solved all
of these problems using your initial preference of what I interpreted
as having all the handlers that actually do stuff to the form within
the Form itself, and have the events follow the class hierarchy so
they end up trickling down to the Form.
1. When A is in a specific state, its thread D should update the
Form's status bar text indicating the duration of time spent in said
specific state using the Form's stopwatch which is controlled by the
buttons on the Form.
2. C is created from A when the Form first loads. In fact, all classes
and threads mentioned are created when the Form first loads. If C
catches an exception, I just wanted to disable the button on the Form
so the application is basically rendered useless but at least it
doesn't crash.
3. A's threads D and E need to log to two list views on the Form. Both
threads need to log to both list views. The list views have multiple
columns and it is all text.
4. A creates multiple B's. B needs to log to only one of the List
Views on the Form, but really the B's can just return an enumeration
back to the caller (thread D of A) do the logging which might be
cleaner anyways.

I am happy with my solution. Thank you for your help. Of course I
would still accept feedback and make appropriate changes as necessary.
.



Relevant Pages

  • Re: Bug in exception handling
    ... The exception that your button1_Click raises is not handled, ... Use add handler in your Main. ... plus a Try/Catch in my Main. ... Try/Catch in Main only catches exceptions if the constructor of the MainForm ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: exiting a constructor early
    ... what exactly happens to any dynamically allocated memory that was ... | obtained before the exception was thrown? ... but for memory that your object attempts to allocate in the constructor, ... you would have to somehow handle that memory in an appropriate handler, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: QC#6682 - is there a fix?
    ... As a rule I terminate my application if an unhandled exception occurs (i.e. ... application's default handler and not my own try...except constructs). ... >>would be to override the form's constructor ... The OnCreate event handler is not called until ...
    (borland.public.delphi.language.objectpascal)
  • Re: QC#6682 - is there a fix?
    ... >one trapped by the default handler). ... corrupted - its an error condition that might be detectable and ... handled without an exception in the first place. ... Aside from the fact that the second is a constructor call which is ...
    (borland.public.delphi.language.objectpascal)
  • Re: Try Finally...
    ... Now we can protect every more or less specialized action ... an error indication (exception or error code) has to be ... an according exception handler can be inserted into the code. ... resources, as they are related to specific actions. ...
    (comp.lang.pascal.delphi.misc)