Passing Variables between classes in modules

okibi okibi at ratedo.com
Thu Apr 26 07:45:02 PDT 2007


Johan Granberg Wrote:

> okibi wrote:
> 
> > I was wondering how I would go about passing a variable between two
> > classes that are within different modules in a program. Here is an example
> > of what I mean:
> > 
> > Let this be modMain:
> > 
> > //begin modMain
> > 
> > module modMain;
> > 
> > //imports go here
> > 
> > import modPopUp;
> > 
> > class modMain : MainWindow //this is for gtkD
> > {
> >   //this() would build the MainWindow
> >   
> >   modPopOp popWindow = new modPopUp();
> > }
> > 
> > void main(char[][] args)
> > {
> >   GtkD.init(args);
> >   modMain mMain = new modMain();
> >   GtkD.main();
> > }
> > 
> > //end modMain
> > 
> > Now let this be modPopUp:
> > 
> > //begin modPopUp
> > 
> > module modPopUp:
> > 
> > //imports go here
> > 
> > class modPopUp : MainWindow
> > {
> >   //this() would build the MainWindow
> >   
> >   char[] myStr;
> >   //function runs to generate myStr
> > }
> > 
> > //end modPopUp
> > 
> > What I'm asking is how do I pass myStr from modPopUp back to modMain?
> > 
> > Thanks!
> 
> Would popWindow.myStr work or have I misunderstood your question?

It doesn't throw an error, however it grabs a null value instead of what the function sets the variable to.


More information about the Digitalmars-d-learn mailing list