unit Frame;interfaceuses
  Windows, Classes, Graphics, Forms, Controls,
  Child, Menus, SysUtils, StdActns, ActnList, Dialogs, ImgList, ComCtrls,
  ToolWin;type
  TMainForm = class(TForm)
    MainMenu1: TMainMenu;
    Window1: TMenuItem;
    New1: TMenuItem;
    File1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    Cascade1: TMenuItem;
    Tile1: TMenuItem;
    ArrangeIcons1: TMenuItem;
    ActionList1: TActionList;
    ActionArrange: TWindowArrange;
    ActionCascade: TWindowCascade;
    ActionClose: TWindowClose;
    ActionMinimizeAll: TWindowMinimizeAll;
    ActionTileHorizontal: TWindowTileHorizontal;
    ActionTileVertical: TWindowTileVertical;
    Tile2: TMenuItem;
    Close1: TMenuItem;
    MinimizeAll1: TMenuItem;
    Edit1: TMenuItem;
    Cut1: TMenuItem;
    Copy1: TMenuItem;
    Paste1: TMenuItem;
    ActionCopy: TEditCopy;
    ActionCut: TEditCut;
    ActionPaste: TEditPaste;
    ActionFont: TAction;
    FontDialog1: TFontDialog;
    N2: TMenuItem;
    Font1: TMenuItem;
    ActionNew: TAction;
    ActionOpen: TAction;
    ActionSaveAs: TAction;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Open1: TMenuItem;
    Save1: TMenuItem;
    ActionSave: TAction;
    Save2: TMenuItem;
    ImageList1: TImageList;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    procedure Exit1Click(Sender: TObject);
    procedure ActionFontExecute(Sender: TObject);
    procedure ActionFontUpdate(Sender: TObject);
    procedure ActionNewExecute(Sender: TObject);
    procedure ActionOpenExecute(Sender: TObject);
    procedure ActionSaveAsExecute(Sender: TObject);
    procedure ActionSaveAsUpdate(Sender: TObject);
    procedure ActionSaveUpdate(Sender: TObject);
    procedure ActionSaveExecute(Sender: TObject);
  private
    { Private declarations }
    Counter: Integer;
  public
    { Public declarations }
  end;var
  MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.Exit1Click(Sender: TObject);
begin
  // automatically closes each child
  Close;
end;procedure TMainForm.ActionFontExecute(Sender: TObject);
begin
  if FontDialog1.Execute then
    (ActiveMDIChild as TChildForm).Memo1.Font :=
      FontDialog1.Font;
end;procedure TMainForm.ActionFontUpdate(Sender: TObject);
begin
  ActionFont.Enabled := MDIChildCount > 0;
end;procedure TMainForm.ActionNewExecute(Sender: TObject);
var
  ChildForm: TChildForm;
begin
  Inc (Counter);
  ChildForm := TChildForm.Create (Self);
  ChildForm.Caption :=
    LowerCase (ExtractFilePath (Application.Exename)) +
    'text' + IntToStr (Counter) + '.txt';
  ChildForm.Show;
end;procedure TMainForm.ActionOpenExecute(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    ActionNewExecute (Self);
    (ActiveMDIChild as TChildForm).Load (OpenDialog1.FileName);
  end;
end;procedure TMainForm.ActionSaveAsExecute(Sender: TObject);
begin
  // suggest the current file name
  SaveDialog1.FileName := ActiveMDIChild.Caption;
  if SaveDialog1.Execute then
  begin
    // modify the file name and save
    ActiveMDIChild.Caption := SaveDialog1.FileName;
    (ActiveMDIChild as TChildForm).Save;
  end;
end;procedure TMainForm.ActionSaveAsUpdate(Sender: TObject);
begin
  ActionSaveAs.Enabled := MDIChildCount > 0;
end;procedure TMainForm.ActionSaveUpdate(Sender: TObject);
begin
  ActionSave.Enabled := (MDIChildCount > 0) and
    (ActiveMDIChild as TChildForm).Modified;
end;procedure TMainForm.ActionSaveExecute(Sender: TObject);
begin
  (ActiveMDIChild as TChildForm).Save;
end;end.unit Child;interfaceuses Windows, Classes, Graphics, Forms, Controls, StdCtrls, Dialogs;type
  TChildForm = class(TForm)
    Memo1: TMemo;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Memo1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    fModified: Boolean;
    procedure SetModified(const Value: Boolean);
  public
    procedure Load (FileName: string);
    procedure Save;
    property Modified: Boolean
      read FModified write SetModified;
  end;var
  ChildForm: TChildForm;implementation{$R *.DFM}procedure TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;procedure TChildForm.Memo1Change(Sender: TObject);
begin
  fModified := True;
end;procedure TChildForm.FormCreate(Sender: TObject);
begin
  fModified := False;
end;procedure TChildForm.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  CanClose := not fModified or (MessageDlg ('Close without saving?',
    mtConfirmation, [mbYes, mbNo], 0) = mrYes);
end;procedure TChildForm.Load (FileName: string);
begin
  Memo1.Lines.LoadFromFile (FileName);
  Caption := FileName;
  fModified := False;
end;procedure TChildForm.Save;
begin
  Memo1.Lines.SaveToFile (Caption);
  fModified := False;
end;procedure TChildForm.SetModified(const Value: Boolean);
begin
  FModified := Value;
end;end.

解决方案 »

  1.   

    object ChildForm: TChildForm
      Left = 266
      Top = 155
      Width = 473
      Height = 294
      Caption = 'MDI Child'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      FormStyle = fsMDIChild
      OldCreateOrder = True
      Position = poDefault
      Visible = True
      OnClose = FormClose
      OnCloseQuery = FormCloseQuery
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object Memo1: TMemo
        Left = 0
        Top = 0
        Width = 465
        Height = 267
        Align = alClient
        TabOrder = 0
        OnChange = Memo1Change
      end
    end
    object MainForm: TMainForm
      Left = 245
      Top = 201
      Width = 435
      Height = 300
      Caption = 'MDI Frame'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -13
      Font.Name = 'System'
      Font.Style = []
      FormStyle = fsMDIForm
      Menu = MainMenu1
      OldCreateOrder = True
      Position = poDefault
      WindowMenu = Window1
      PixelsPerInch = 96
      TextHeight = 16
      object ToolBar1: TToolBar
        Left = 0
        Top = 0
        Width = 427
        Height = 29
        Caption = 'ToolBar1'
        Images = ImageList1
        TabOrder = 0
        object ToolButton1: TToolButton
          Left = 0
          Top = 2
          Action = ActionNew
        end
        object ToolButton2: TToolButton
          Left = 23
          Top = 2
          Action = ActionOpen
        end
        object ToolButton3: TToolButton
          Left = 46
          Top = 2
          Action = ActionSave
        end
        object ToolButton4: TToolButton
          Left = 69
          Top = 2
          Action = ActionClose
        end
        object ToolButton5: TToolButton
          Left = 92
          Top = 2
          Width = 8
          Caption = 'ToolButton5'
          ImageIndex = 4
          Style = tbsSeparator
        end
        object ToolButton6: TToolButton
          Left = 100
          Top = 2
          Action = ActionCut
        end
        object ToolButton7: TToolButton
          Left = 123
          Top = 2
          Action = ActionCopy
        end
        object ToolButton8: TToolButton
          Left = 146
          Top = 2
          Action = ActionPaste
        end
      end
      object MainMenu1: TMainMenu
        Images = ImageList1
        Left = 24
        Top = 128
        object File1: TMenuItem
          Caption = '&File'
          object New1: TMenuItem
            Action = ActionNew
          end
          object Open1: TMenuItem
            Action = ActionOpen
          end
          object Save2: TMenuItem
            Action = ActionSave
          end
          object Save1: TMenuItem
            Action = ActionSaveAs
          end
          object Close1: TMenuItem
            Action = ActionClose
          end
          object N1: TMenuItem
            Caption = '-'
          end
          object Exit1: TMenuItem
            Caption = '&Exit'
            OnClick = Exit1Click
          end
        end
        object Edit1: TMenuItem
          Caption = 'Edit'
          object Cut1: TMenuItem
            Action = ActionCut
          end
          object Copy1: TMenuItem
            Action = ActionCopy
          end
          object Paste1: TMenuItem
            Action = ActionPaste
          end
          object N2: TMenuItem
            Caption = '-'
          end
          object Font1: TMenuItem
            Action = ActionFont
          end
        end
        object Window1: TMenuItem
          Caption = '&Window'
          object Cascade1: TMenuItem
            Action = ActionCascade
          end
          object Tile2: TMenuItem
            Action = ActionTileVertical
          end
          object Tile1: TMenuItem
            Action = ActionTileHorizontal
          end
          object ArrangeIcons1: TMenuItem
            Action = ActionArrange
          end
          object MinimizeAll1: TMenuItem
            Action = ActionMinimizeAll
          end
        end
      end
      object ActionList1: TActionList
        Images = ImageList1
        Left = 24
        Top = 72
        object ActionArrange: TWindowArrange
          Category = 'Window'
          Caption = '&Arrange Icons'
        end
        object ActionCascade: TWindowCascade
          Category = 'Window'
          Caption = '&Cascade'
          ImageIndex = 17
        end
        object ActionClose: TWindowClose
          Category = 'Window'
          Caption = '&Close'
          ImageIndex = 3
        end
        object ActionMinimizeAll: TWindowMinimizeAll
          Category = 'Window'
          Caption = '&Minimize All'
        end
        object ActionTileHorizontal: TWindowTileHorizontal
          Category = 'Window'
          Caption = 'Tile &Horizontal'
          ImageIndex = 15
        end
        object ActionTileVertical: TWindowTileVertical
          Category = 'Window'
          Caption = 'Tile &Vertical'
          ImageIndex = 16
        end
        object ActionCopy: TEditCopy
          Category = 'Edit'
          Caption = '&Copy'
          Hint = 'Copy'
          ImageIndex = 1
          ShortCut = 16451
        end
        object ActionCut: TEditCut
          Category = 'Edit'
          Caption = 'Cu&t'
          Hint = 'Cut'
          ImageIndex = 0
          ShortCut = 16472
        end
        object ActionPaste: TEditPaste
          Category = 'Edit'
          Caption = '&Paste'
          Hint = 'Paste'
          ImageIndex = 2
          ShortCut = 16470
        end
        object ActionFont: TAction
          Category = 'Edit'
          Caption = '&Font...'
          ImageIndex = 7
          ShortCut = 16454
          OnExecute = ActionFontExecute
          OnUpdate = ActionFontUpdate
        end
        object ActionNew: TAction
          Category = 'File'
          Caption = '&New'
          ImageIndex = 4
          OnExecute = ActionNewExecute
        end
        object ActionOpen: TAction
          Category = 'File'
          Caption = '&Open...'
          ImageIndex = 5
          ShortCut = 16463
          OnExecute = ActionOpenExecute
        end
        object ActionSaveAs: TAction
          Category = 'File'
          Caption = 'Save &As...'
          OnExecute = ActionSaveAsExecute
          OnUpdate = ActionSaveAsUpdate
        end
        object ActionSave: TAction
          Category = 'File'
          Caption = '&Save'
          ImageIndex = 6
          ShortCut = 16467
          OnExecute = ActionSaveExecute
          OnUpdate = ActionSaveUpdate
        end
      end
      object FontDialog1: TFontDialog
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'MS Sans Serif'
        Font.Style = []
        MinFontSize = 0
        MaxFontSize = 0
        Left = 96
        Top = 128
      end
      object OpenDialog1: TOpenDialog
        Filter = 'Text file (*.txt)|*.txt|Any file (*.*)|*.*'
        Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]
        Left = 176
        Top = 136
      end
      object SaveDialog1: TSaveDialog
        Filter = 'Text file (*.txt)|*.txt|Any file (*.*)|*.*'
        Options = [ofHideReadOnly, ofPathMustExist, ofEnableSizing]
        Left = 168
        Top = 80
      end
      

  2.   

    object ImageList1: TImageList
        Left = 100
        Top = 76
        Bitmap = {}  end
    end