Is there anyway to do this?
Every time any button is click inside class Form1, MyButtomArray.CharArray
(MyButtomArray is a class) gets set (or reset) (bool). Once this is done the
class TEC gets executed. I want to access MyButtonArray.CharArray to get the
bool values in TEC.
Any ideas?
Scott 5 2033
Scott,
You could consider making the bool field(s) static. This means they will be
visible to any class or method in any assembly that has access to your TEC
class, without having an instance of the class, via "TEC.MyBoolFieldName". Be
aware that if you choose this route, and if your business logic dictates,
some locking semantics may be required.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Scott Starker" wrote: Is there anyway to do this?
Every time any button is click inside class Form1, MyButtomArray.CharArray (MyButtomArray is a class) gets set (or reset) (bool). Once this is done the class TEC gets executed. I want to access MyButtonArray.CharArray to get the bool values in TEC.
Any ideas?
Scott
Peter,
I created a version of static fields and it worked. But there may be two (or
more) ButtonArray's in my program I decided to make it non-static. Can I not
share a non-static variable of one class with 2 or more classes?
Scott
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:B1**********************************@microsof t.com... Scott, You could consider making the bool field(s) static. This means they will be visible to any class or method in any assembly that has access to your TEC class, without having an instance of the class, via "TEC.MyBoolFieldName". Be aware that if you choose this route, and if your business logic dictates, some locking semantics may be required.
Peter -- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Scott Starker" wrote:
Is there anyway to do this?
Every time any button is click inside class Form1, MyButtomArray.CharArray (MyButtomArray is a class) gets set (or reset) (bool). Once this is done the class TEC gets executed. I want to access MyButtonArray.CharArray to get the bool values in TEC.
Any ideas?
Scott
The only way to "share" a non-static variable between classes is by passing
a reference to the class that contains the variables to the other classes.
In other words if you want to access a method, variable or property in a
class you need to have an instance of the class or make them static.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Scott Starker" <Sc***********@sil.org> wrote in message
news:eM*************@TK2MSFTNGP12.phx.gbl... Peter,
I created a version of static fields and it worked. But there may be two (or more) ButtonArray's in my program I decided to make it non-static. Can I not share a non-static variable of one class with 2 or more classes?
Scott
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message news:B1**********************************@microsof t.com... Scott, You could consider making the bool field(s) static. This means they will be visible to any class or method in any assembly that has access to your TEC class, without having an instance of the class, via "TEC.MyBoolFieldName". Be aware that if you choose this route, and if your business logic dictates, some locking semantics may be required.
Peter -- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Scott Starker" wrote:
Is there anyway to do this?
Every time any button is click inside class Form1, MyButtomArray.CharArray (MyButtomArray is a class) gets set (or reset) (bool). Once this is done the class TEC gets executed. I want to access MyButtonArray.CharArray to get the bool values in TEC.
Any ideas?
Scott
If you have a parent form you can create the TEC instance there, and pass it
as a parameter in the constructor to other forms, ensuring the same instance
is used throughout. Then just expose your bools as properties of TEC. You
could also create the TEC instance in your main method and pass it in the
constructor for your Form1.
But if the ButtonArrays are getting the values from TEC after TEC "executes"
then you might consider creating an event in TEC and an EventArgs to hold
your boolean values. Then subscribe to the event in Form1. Each time TEC
fires, Form1 will have access to those boolean values.
HTH
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Scott Starker" wrote: Peter,
I created a version of static fields and it worked. But there may be two (or more) ButtonArray's in my program I decided to make it non-static. Can I not share a non-static variable of one class with 2 or more classes?
Scott
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message news:B1**********************************@microsof t.com... Scott, You could consider making the bool field(s) static. This means they will be visible to any class or method in any assembly that has access to your TEC class, without having an instance of the class, via "TEC.MyBoolFieldName". Be aware that if you choose this route, and if your business logic dictates, some locking semantics may be required.
Peter -- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Scott Starker" wrote:
Is there anyway to do this?
Every time any button is click inside class Form1, MyButtomArray.CharArray (MyButtomArray is a class) gets set (or reset) (bool). Once this is done the class TEC gets executed. I want to access MyButtonArray.CharArray to get the bool values in TEC.
Any ideas?
Scott
What are the relationships between Form1, MyButtonArray, and TEC?
For example, is MyButtonArray stored inside Form1 and so there is one
MyButtonArray for each Form1, or is it completely independent from
Form1, except that it's supposted to react to a button there? Is there
one, global TEC class, or are there several? How does the TEC class
know which MyButtonArray it's supposed to look at?
Do you see the sort of thing I'm getting at here? There are
relationships between these classes: aggregation (one class is a field
in another class), or one-to-one, or one-to-many, or many-to-many...
that sort of thing.
How classes communicate has everything to do with how they are related.
Without knowing how the classes are related, we can't tell you how to
make them communicate successfully. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark Sisson |
last post by:
Hi all.
SITUATION
================
1. I have a base class with a member variable that's an object
2. I have several classes that inherit from the base class.
3. There are several methods in...
|
by: Tony Fonager |
last post by:
I am currently developing a statistics system in ASP.NET, and need to share
information about the customers websites, in this application.
(I have simplified my code, to make my project easier to...
|
by: Tony Fonager |
last post by:
I am currently developing a statistics system in ASP.NET, and need to share
information about the customers websites, in this application.
(I have simplified my code, to make my project easier to...
|
by: WXS |
last post by:
Vote for this idea if you like it here:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
|
by: Valeriu Catina |
last post by:
Hi,
consider the Shape class from the FAQ:
class Shape{
public:
Shape();
virtual ~Shape();
virtual void draw() = 0;
|
by: Bob Johnson |
last post by:
I have a base class that must have a member variable populated by, and only
by, derived classes.
It appears that if I declare the variable as "internal protected" then the
base class *can*...
|
by: Henri.Chinasque |
last post by:
Hi all,
I am wondering about thread safety and member variables. If I have
such a class:
class foo {
private float m_floater = 0.0;
public void bar(){
m_floater = true;
}
|
by: Immortal Nephi |
last post by:
First class is the base class. It has two data: m_Base1 and m_Base2.
Second class and third class are derived classes and they are derived
from first class. m_Base1 and m_Base2 are inherited into...
|
by: Juha Nieminen |
last post by:
As we know, the keyword "inline" is a bit misleading because its
meaning has changed in practice. In most modern compilers it has
completely lost its meaning of "a hint for the compiler to inline...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |