Results 1 to 3 of 3

Thread: Need to provide variables from Main to all other classes

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    36

    Need to provide variables from Main to all other classes

    Hi all,

    I have a need to provide mouse coordinates and click details to the sub-classes of an application. The details are stored in a typed variable in the main class, as they are not processed when the event occurs.

    What is the correct way of getting the classes to refer to variables in the parent class that instigated them? I realise this is not standard practise, but at this stage in the project I am converting code from a procedural language and need to do this as an intermediary step. Using the mouse events is also not possible, as this is a DirectX-oriented real-time program, and some things still have to be processed procedurally. They have to be stored via the event and then processed manually.

    I may have dozens of instances of the classes, so distributing the mouse data every time it changes is not a good option. Ideally, the class should be able to retrieve the data when it needs it.

    Thanks in advance.

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    36

    Re: Need to provide variables from Main to all other classes

    I have my answer, I think! I can fully declare the variable including class name, and it works.

    Although it is a workaround, I would like to be able to use some kind of "parent" notation rather than explicitly use the class name, it gives me a little more flexibility. Is this possible?

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Need to provide variables from Main to all other classes

    A class should not need to know about anything external to itself. Therefore, if a class needs to access any variable, including forms and controls, that are not members of the class, then to do it right, pass the variable to the class. This can be done during construction by creating a Sub New that takes the variable as an argument, or it can be done at some later time via a property or method of the class.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width