robertkjr3d
Programmer
How do I programmatically call a member of an unknown type?
I have form A... which opens up another form B. However Form A will be the parent of B.
In fact I have this code:
In list1 parent is an object. Because it could come from any number of forms.
Now in the 'listing' code... I want to call a member of parent... unfortunately I can't do this normally by either:
gives the compile error that object parent contains no definition of 'whatever'.
The other way that I know will work is to have a series of if/case statments that figure out where it did come from:
But isn't there a way I can programmatically find the objects and call them of the object parent without having to know before compile time what form is the parent?
Of course I would make sure that all the 'Parents' would have the 'whatever' I'm trying to reference. But I shouldn't have to know.. or use a series of case or if statements to do this.
-Robert
I have form A... which opens up another form B. However Form A will be the parent of B.
In fact I have this code:
Code:
listing list1 = new listing();
list1.parent = this;
list1.Show();
In list1 parent is an object. Because it could come from any number of forms.
Now in the 'listing' code... I want to call a member of parent... unfortunately I can't do this normally by either:
Code:
parent.whatever = 0;
The other way that I know will work is to have a series of if/case statments that figure out where it did come from:
Code:
if (source == "Referral")
{
Referral r = (Referral)parent;
r.whatever = 0; //and this will work
}
But isn't there a way I can programmatically find the objects and call them of the object parent without having to know before compile time what form is the parent?
Of course I would make sure that all the 'Parents' would have the 'whatever' I'm trying to reference. But I shouldn't have to know.. or use a series of case or if statements to do this.
-Robert