Dear All,
What is the best practice to organize calling methods between parent and child forms.
For example I would like to call a method in the parent form.
Should I forward the object handle of this parent to the child when I initialize this or is this automatically done and can I obtain this object handle within each child form that opens within the application.
Kind regards,
Peter
Well, if you just pass the object reference to the child you create a rather strong dependency. Say, the child needs to run the Update method in the parent you can do two things: create an IUpdatable interface (with the Update method), implement the IUpdatable in the parent and pass the object reference from parent to child as an IUpdatable. Then you child form can be used for any parent which implement IUpdatable. Second possibility is events. Subscribe the parent to the update events from the child. (I'm using Update as an example obviously).
Huh? A parent and child class are one class. Any method that is public or protected in the parent is callable from the child with no object reference needed (though you can use THIS-OBJECT if you want). It is just like calling a method in yourself.
Hello Laura,
The parent class (.Net form) instance the client class which is another .Net form.
The child is not an inherited class of the parent in this case.
Hello Bronco,
Setting the Parent Object as Property in the Child .Net form would not be that difficult.
What kind of class definitions should I use for this?
Then I could assign THIS-OBJECT of the parent to the Object property into the child.
Calling the procedure like ParentFrom:UpdateDataset(input-output dataset dsData).
Regards,
Peter.
Sure that's possible, but my point is that in OO you try keep the dependencies between classes as little as possible so they can be reused easier. One other thing, why don't you pass the dataset from parent to child by-reference?
PS. I was reacting to the OP, not Peter Judge's post :-)
Bronco,
Passing the datasets by reference is an option as well.
Need to pass more then one in this case.
Peter
Bronco,
I have tried to pass them by reference.
But this did not populate the main data set with referential names.
Second time a passed them as input data sets without by reference.
After that the data-set completed with the names.
This helped to solve the issue. But will look into the links Peter Judge mentioned.
Kind regards,