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 Problem 1

Status
Not open for further replies.

LastCyborg

Programmer
Feb 7, 2003
256
MX
I'm making an MDI editor, but I got some problems with the save as, print and others functions

The problem is that when I have >=2 new sheets and I choose the save,save as or print functions this functions don't work with the active child window.

For example if I have 3 sheets and the caption for each one of this are:

Window1, Window2, Window3, respectivelly, & I have active (focused) Window3, I select print function, but the program prints the sometimes Window1, sometimes Window2 or Window3,so what can I do to solve this problem?
 
Post the code here that you are using for your save function and we will see if we can help you.
 
I'm using a SaveDialog component, and what I want to know is how can I to specify (to the SaveDialog component)which child form is gonna be saved

--- LastCyborg ---
 
The SaveDialog component only gives you back a filename. It does not do the actual save. What code are you using to actually save, what is it you are saving, a graphic?
 
I have not the code, because I don't know how to code that.

I think there was a misunderstand, I don't wanna save them all at same time.

I want just that if I have 3 child fomrs and the 2nd is focused and the user selects save, only the 2nd child form must be saved, but the problem is that I don't know how to make reference to the 2nd childform.

to save his content I use:
RichEdit1->Lines->SaveToFile (SaveDialog->FileName);



--- LastCyborg ---
 
Have a look in the manual at
Code:
MDIChildren
.

Index 0 will always be the MDI child form with focus (eg).

Code:
if (frmMain.MDIChildCount > 0) then
      ShowMessage(frmMain.MDIChildren[0].Name);

Now that we have a pointer to the focused MDI child form, we need a way of making that form do something for us. I have found the easiest way is to define a form type of my own which has the functions I need, then I can typecast a call to this form. I will show you ...

In your main form unit, above the class declaration add another class declaration something like this:
Code:
  TMyForm = class(TForm)
  private
  public
    procedure DoMySave(); virtual;
  end; //class

Down in the implementation section of your main form unit you need something like this:

Code:
procedure TMyForm.SaveData;
begin
  // virtual procedure
end;

Now, in the unit for your MDI child window, change the class definition at the top of the unit from TForm to TMyForm.
You will also need to add the DoMySave procedure to the public section of this class definition (using override). Now put the code for saving into this procedure now (in the unit for your MDI child window).
Code:
  TfrmMDIMyChild = class(TMyForm)
    {...All the components will be in here...}
  private
  public
    procedure DoMySave; override;
  end;

Back in your main form unit, the code to save will now look like this:
Code:
if (frmMain.MDIChildCount > 0) then
      TMyForm(frmMain.MDIChildren[0]).DoMySave;

Let me know how you go with all this :)
Tim
SNL Computing

 
If you only have ONE type of MDI Child form, you could skip all the bits about defining your own form type and just use the line of code at the bottom of the post. Put the typename of your form where I have put TMyForm.
Code:
if (frmMain.MDIChildCount > 0) then
      TYourFormType(frmMain.MDIChildren[0]).RichEdit1.Lines.SaveToFile;
Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top