C# Win App class problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pod
    Contributor
    • Sep 2007
    • 298

    C# Win App class problem

    I am trying to split my code over several class files but I am having problems accessing them.

    I guess I have a hard time with inheritance.

    Here's is my setup:

    I have a file called OVRform which contains all the code behind for the form.
    Code:
    namespace Tracking_WIN
    {
        public partial class OVRform : Form
    ...

    I have another file, a class file called audit.cs and here is all of the code
    Code:
    namespace Tracking_WIN
    {
        public partial class audit : OVRform
        {
            public string dojo
            {
                get { return doubleJeopardy(); }
            }
    
            public string doubleJeopardy()
            {
    
                try
                {
                    return "yes";
                }
                catch
                {
                    return "no";
                }
            }
        }
    }

    How can I get access to the dojo property of the audit object from the OVRform ?

    Am I being clear enough?


    Thanks for any response


    Perry
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Short Answer: You can't.
    You would need an instance of audit to manipulate members created in the audit class.

    For an easy demonstration.
    Create an instance of Control and of say ListBox.
    ListBox derives from control (inherits)
    But Control cannot use a .SelectedItem property because it's not a ListBox.

    Comment

    • pod
      Contributor
      • Sep 2007
      • 298

      #3
      OK, I created an instance of audit and can get to the dojo property.

      Code:
                  audit auditObj = new audit();
      But something strange happens...

      If this instance is set in the main loading function I get an infinite loop, creating the audit instance reloads the form which recreates the audit instance ....



      Code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Configuration;
      using System.Data;
      using System.Data.OleDb;
      using System.Drawing;
      using System.Security.Principal;
      using System.Text;
      using System.Windows.Forms;
      
      using winDBtools;
      using customFunctions;
      
      namespace Tracking_WIN
      {
          public partial class OVRform : Form
          {
      
              public OVRform()           //generated function
              {
                  InitializeComponent(); //generated function
                  InitEnv();
              }
      I have a lot of learning to do, I ordered a book, I hope it has a clear picture of the Object Oriented Programming :)

      Comment

      Working...