Overclock.net banner

1 - 7 of 7 Posts

·
Registered
Joined
·
187 Posts
Is Form2 created by Form1 or vice versa?

If Form1 creates Form2 then you can simply pass your variables to Form2 in the constructor or via Access functions (Get/Set).

If Form1 is created by Form2 you need to use Get functions to pull the values out.

I'll post example code when I get home from work if you need it.
 

·
Registered
Joined
·
2,005 Posts
Discussion Starter #3
Quote:

Originally Posted by Safetydan View Post
Is Form2 created by Form1 or vice versa?

If Form1 creates Form2 then you can simply pass your variables to Form2 in the constructor or via Access functions (Get/Set).

If Form1 is created by Form2 you need to use Get functions to pull the values out.

I'll post example code when I get home from work if you need it.

That would be great! thanks!
 

·
Registered
Joined
·
821 Posts
Code:

Code:
void Form1::Foo()
{
    // Pass just the data to Form2
    Form2 form2 = new Form2(A(), B(), C());

    // ...
}
or

Code:

Code:
void Form1::Foo()
{
    // Reduce coupling between the two objects by just passing a small/specific 
    // interface to Form2  i.e. don't pass the entire Form.
    Form2 form2 = new Form2((ISmallSpecificInterface)this);

    // ...
}

public interface ISmallSpecificInterface
{
    string A { get;  set; }
}
 

·
Premium Member
Joined
·
15,202 Posts
Quote:

Originally Posted by linskingdom View Post
Or you can create a public property in form1 so call the property from from2.

//In form1

private String _var1;

public String Var1
{
get { return _var1; }
}

//in form2.

private String _var1from1;
_var1from1=form1.Var1();

...You just taught me something today. Thank you.
 
1 - 7 of 7 Posts
Top