Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI parent/child

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
I have created a text editor, with my main form being an MDI parent. The user can dynamically create multiple children (text pages) thats no problem... my problem is this:

If they are typing in one child and they want to save their work, I need to specify which child form is focused, in use, whatever to save the right one. I don't want to save every child, just the one the user has been using. I need a way to find that individual form.
There's probably a way to do this, but I don't know it. Does anyone else? Cyprus
 
Screen->ActiveForm will retreive the handle to the currently active MDI form. Hope this helps.

Karthik S
 
Alright... heres my problem. I can access an individual form just fine, I have a rich edit on each individual MDI child, and when a user types in that rich edit and wants to save what he typed in it, he presses save...
that's all fine and dandy.

the problem is that when I access individual forms, I cant access the richedit. the methods i've used for accessing forms (Form1->MDIChildren, Screen->ActiveForm...) catch a plain old form. it can only use the references to a generic blank form, such as Left, Caption, etc... Not my rich edit. i need to be able to grab a handle to the richedit that the user has just used and is trying to save so that I can save the work they did in the richedit.

clear as mud?? Cyprus
 
Yep.
You can create a new menu in the Child form with all the save/open options and merge it with the menu in the MDI Parent form. In this case when the child form opens, the menu corresponding to the child form will merge into the main menu of the MDI Parent. I had faced this scenario in my app and solved it in this way. But for this you need to set the merge property for the menus in design mode. ( I did this in trial and error by changing the merge properties and worked good.

Karthik
 
All you have to do is allocate a new pointer to child form and make it pointing to the currently active child form, for example:

Code:
TMDIChild *Child;
Child = (TMDIChild *)MDIChildren[0];

then you can use everythingh is on the child form as you normally would!!!

Code:
Child->RichEdit1->...

Bye, Rolandfg
 
Thank you, Rolandfg.

That was what I was looking for, but for some reason I wasn't getting the same result.

Cyprus
 
Wait a second...

It keeps giving me the error saying TMDIChild is undefined. What's the matter?

Alright, This is how I dynamically created the Child in the first place, the FormStyle, of course, being fsMDIChild. Does that help at all?

TEditBox *EditBox = new TEditBox(Application);
EditBox->Caption = "Untitled";

Now when I try to implement your code,

TMDIChild *Child;
Child = (TMDIChild *)MDIChildren[0];

Child->RichEdit1->Lines->SaveToFile(SaveDialog1 >FileName);


It tells me TMDIChild is undefined. I also tried this code:


dynamic_cast<TMDIChild*>(MDIChildren[0])->RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);

but it gives me a message saying type name is expected after the <TMDIChild* part. Im throuoghly stuck, any suggestions on either of these peoblems??
Cyprus
 
My code was just a sample! Your code must be

Code:
TEditBox *Child;
Child = (TEditBox *)MDIChildren[0];
Child->RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);

This should be done in Main Parent form otherwise MDIChilder property will not exists (but from the error I guess you are already in the main parent form). Bye, Rolandfg
 
Yes, I realized that just a bit too late. My apologies for wasting your time.

Sorry about that &quot;Blonde Moment&quot;

Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top