Global class

  • Thread starter Thread starter pOtrek
  • Start date Start date
P

pOtrek

I'm new to c# and visual studio, previously i've been using borland
compilers like Delphi, so i have 2 questions:

I want to do class that every other class/forms have access to (i want
to store program configuration there). How should i do it (or where
sould i declare variable that points to this class) without using
static proprties ??

My second problem is how to get access to global methods from main
form class (class that starts the program) from other classes/forms

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
If you have a MainForm class

Then whenever you call a ChildForm pass on the MainForm Pointer like this


ChildForm oChildForm = new ChildForm()
oChildForm.PerformHandShake(this)


In the ChildForm Class

Define as follows

MainForm MainFormPointer ;

void PerformHandShake(MainForm mainformptr)
{
this.MainFormPointer = mainformptr ;
}

From this point onwards you will have all the access to the MainForm
variables and methods from this ChildForm.

Hope this helps


Anand
 
pOtrek said:
I'm new to c# and visual studio, previously i've been using borland
compilers like Delphi, so i have 2 questions:

I want to do class that every other class/forms have access to (i want
to store program configuration there). How should i do it (or where
sould i declare variable that points to this class) without using
static proprties ??

My second problem is how to get access to global methods from main
form class (class that starts the program) from other classes/forms

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Another option for you is for you to create your Options class as a
singleton (google is your friend here for some good example code)

Then rather than keeping track of a global variable you just call the
static instance (or whatever you call it) method to get your config
class instance...

string connString = Config.Instance.GetSomeConnectionString();

Regards Tim Jarvis.
 
Back
Top