Solved

Caption MDIform

Posted on 2000-04-29
5
360 Views
Last Modified: 2010-04-04
Hello,

I have an MDIform (Main form) and a few MDIchildforms.  Everytime an MDIchild become active, the caption of the Main form (MDIform) will be changed.  Ex.  The caption 'Mainform' will be changed in 'Mainform - [Customers]'.  Even when the caption of the MDIchild is blank, the caption of the Mainform will be changed.  Ex. 'Mainform - []'.

Is it possible to avoid changes to the caption of the Mainform.

Thanks, Dirk.

PS sorry for my poor English.
0
Comment
Question by:ka1a
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Mathias
ID: 2763415
Listening...
0
 

Author Comment

by:ka1a
ID: 2763895
TDS,

What do you mean with 'Listening' ???

Thanks, Dirk.

PS sorry for my poor English.
0
 
LVL 3

Expert Comment

by:Mathias
ID: 2763959
For German:

Listening: Ich bleibe an der Sache dran!

For English:

I will work on this question.
0
 

Author Comment

by:ka1a
ID: 2764001
Thanks,

I hope you find a solution.

Dirk.
0
 
LVL 3

Accepted Solution

by:
Mathias earned 25 total points
ID: 2764095
I will explain my solution. In your "demos\doc\textedit" directory
is an example called "textedit.dpr". Open this project and replace
the code with the following code.

You must only add these procedures
into your object inspector (MDIEdit):

OnActivate -> Click on arrow and choose OnActivate
OnDeActivate -> Click on arrow and choose OnDeActivate
OnResize -> Click on arrow and choose OnResize

Sorry for the huge code example, but it was easier to show it as
to describe it.

{ - - - - - - - - - - - - - - - - - - - - - - }

{Main file}

unit MDIFrame;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  Menus;

type
  TFrameForm = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    New1: TMenuItem;
    Open1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    Window1: TMenuItem;
    Tile1: TMenuItem;
    Cascade1: TMenuItem;
    Arrangeicons1: TMenuItem;
    OpenFileDialog: TOpenDialog;
    procedure Exit1Click(Sender: TObject);
    procedure New1Click(Sender: TObject);
    procedure Tile1Click(Sender: TObject);
    procedure Cascade1Click(Sender: TObject);
    procedure Arrangeicons1Click(Sender: TObject);
    procedure Open1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    OrigName: String;
  public
    { Public declarations }
    function GetOrigName: String;
  end;

var
  FrameForm: TFrameForm;

implementation

uses MDIEdit;

{$R *.DFM}

procedure TFrameForm.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TFrameForm.New1Click(Sender: TObject);
begin
  TEditForm.Create(Self);
end;

procedure TFrameForm.Tile1Click(Sender: TObject);
begin
  Tile;
end;

procedure TFrameForm.Cascade1Click(Sender: TObject);
begin
  Cascade;
end;

procedure TFrameForm.Arrangeicons1Click(Sender: TObject);
begin
  ArrangeIcons;
end;

procedure TFrameForm.Open1Click(Sender: TObject);
begin
  if OpenFileDialog.Execute then
  with TEditForm.Create(Self) do
    Open(OpenFileDialog.FileName);
end;

procedure TFrameForm.FormCreate(Sender: TObject);
begin
  OrigName:=Caption;
end;

function TFrameForm.GetOrigName: String;
begin
  GetOrigName:=OrigName;
end;

end.

{ - - - - - - - - - - - - - - - - - - - - - - }

{unit MDIEdit}

unit MDIEdit;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls, ComCtrls;

type
  TEditForm = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    New1: TMenuItem;
    Open1: TMenuItem;
    Save1: TMenuItem;
    Saveas1: TMenuItem;
    Print1: TMenuItem;
    N2: TMenuItem;
    Exit1: TMenuItem;
    Edit1: TMenuItem;
    Cut1: TMenuItem;
    Copy1: TMenuItem;
    Paste1: TMenuItem;
    Delete1: TMenuItem;
    N3: TMenuItem;
    Selectall1: TMenuItem;
    Character1: TMenuItem;
    Left1: TMenuItem;
    Right1: TMenuItem;
    Center1: TMenuItem;
    N4: TMenuItem;
    Wordwrap1: TMenuItem;
    N5: TMenuItem;
    Font1: TMenuItem;
    Editor: TRichEdit;
    PopupMenu1: TPopupMenu;
    Cut2: TMenuItem;
    Copy2: TMenuItem;
    Paste2: TMenuItem;
    SaveFileDialog: TSaveDialog;
    FontDialog1: TFontDialog;
    Printersetup1: TMenuItem;
    Close1: TMenuItem;
    PrinterSetupDialog1: TPrinterSetupDialog;
    PrintDialog1: TPrintDialog;
    procedure Exit1Click(Sender: TObject);
    procedure New1Click(Sender: TObject);
    procedure AlignClick(Sender: TObject);
    procedure Wordwrap1Click(Sender: TObject);
    procedure Cut1Click(Sender: TObject);
    procedure Copy1Click(Sender: TObject);
    procedure Paste1Click(Sender: TObject);
    procedure Selectall1Click(Sender: TObject);
    procedure Delete1Click(Sender: TObject);
    procedure Edit1Click(Sender: TObject);
    procedure Saveas1Click(Sender: TObject);
    procedure Save1Click(Sender: TObject);
    procedure Font1Click(Sender: TObject);
    procedure Close1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Printersetup1Click(Sender: TObject);
    procedure Print1Click(Sender: TObject);
    procedure Open1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
    SaveName, PathName: string;
  public
    { Public declarations }
    procedure Open(const AFileName: string);
  end;

var
  EditForm: TEditForm;

const
  DefaultFileName = 'Untitled';

implementation

uses Clipbrd, Printers, MDIFrame;

{$R *.DFM}

procedure TEditForm.Exit1Click(Sender: TObject);
begin
  FrameForm.Exit1Click(Sender);
end;

procedure TEditForm.New1Click(Sender: TObject);
begin
  FrameForm.New1Click(Sender);
end;

procedure TEditForm.Open1Click(Sender: TObject);
begin
  FrameForm.Open1Click(Sender);
end;

procedure TEditForm.AlignClick(Sender: TObject);
begin
  Left1.Checked := False;
  Right1.Checked := False;
  Center1.Checked := False;
  with Sender as TMenuItem do Checked := True;
  with Editor.Paragraph do
    if Left1.Checked then
      Alignment := taLeftJustify
    else if Right1.Checked then
      Alignment := taRightJustify
    else if Center1.Checked then
      Alignment := taCenter;
end;

procedure TEditForm.Wordwrap1Click(Sender: TObject);
begin
  with Editor do
  begin
    WordWrap := not WordWrap; { toggle word wrapping }
    if WordWrap then
      ScrollBars := ssVertical
    else
      ScrollBars := ssBoth;
    WordWrap1.Checked := WordWrap; { set menu item check }
  end;
end;

procedure TEditForm.Cut1Click(Sender: TObject);
begin
  Editor.CutToClipboard;
end;

procedure TEditForm.Copy1Click(Sender: TObject);
begin
  Editor.CopyToClipboard;
end;

procedure TEditForm.Paste1Click(Sender: TObject);
begin
  Editor.PasteFromClipboard;
end;

procedure TEditForm.Selectall1Click(Sender: TObject);
begin
  Editor.SelectAll;
end;

procedure TEditForm.Delete1Click(Sender: TObject);
begin
  Editor.ClearSelection;
end;

procedure TEditForm.Edit1Click(Sender: TObject);
var
  HasSelection: Boolean;
begin
  Paste1.Enabled := Clipboard.HasFormat(CF_TEXT);
  Paste2.Enabled := Paste1.Enabled;
  HasSelection := Editor.SelLength > 0;
  Cut1.Enabled := HasSelection;
  Cut2.Enabled := HasSelection;
  Copy1.Enabled := HasSelection;
  Copy2.Enabled := HasSelection;
  Delete1.Enabled := HasSelection;
end;

procedure TEditForm.Open(const AFileName: string);
begin
  PathName := AFileName;
  Caption := ExtractFileName(AFileName);
  FrameForm.Caption:=SaveName+' ['+Caption+']';
  with Editor do
  begin
    Lines.LoadFromFile(PathName);
    SelStart := 0;
    Modified := False;
  end;
end;

procedure TEditForm.Saveas1Click(Sender: TObject);
begin
  SaveFileDialog.FileName := PathName;
  if SaveFileDialog.Execute then
  begin
    PathName := SaveFileDialog.FileName;
    Caption := ExtractFileName(PathName);
    FrameForm.Caption:=SaveName+' ['+Caption+']';
    Save1Click(Sender);
  end;
end;

procedure TEditForm.Save1Click(Sender: TObject);
begin
  if PathName = DefaultFileName then
    SaveAs1Click(Sender)
  else
  begin
    Editor.Lines.SaveToFile(PathName);
    Editor.Modified := False;
  end;
end;

procedure TEditForm.Font1Click(Sender: TObject);
begin
  FontDialog1.Font := Editor.Font;
  if FontDialog1.Execute then
    Editor.SelAttributes.Assign(FontDialog1.Font);
end;

procedure TEditForm.Close1Click(Sender: TObject);
begin
  Close;
end;

procedure TEditForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TEditForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
const
  SWarningText = 'Save changes to %s?';
begin
  if Editor.Modified then
  begin
    case MessageDlg(Format(SWarningText, [PathName]), mtConfirmation,
      [mbYes, mbNo, mbCancel], 0) of
      idYes: Save1Click(Self);
      idCancel: CanClose := False;
    end;
  end;
  if FrameForm.MDIChildCount = 1 then {1, because this is the last MDI which is opened}
    FrameForm.Caption:=FrameForm.GetOrigName;
end;

procedure TEditForm.FormCreate(Sender: TObject);
begin
  PathName := DefaultFileName;
  SaveName := FrameForm.GetOrigName;
end;

procedure TEditForm.Printersetup1Click(Sender: TObject);
begin
  PrinterSetupDialog1.Execute;
end;

procedure TEditForm.Print1Click(Sender: TObject);
begin
  if PrintDialog1.Execute then
    Editor.Print(PathName);
end;

procedure TEditForm.FormActivate(Sender: TObject);
begin
  FrameForm.Caption:=SaveName+' ['+Caption+']';
end;

procedure TEditForm.FormDeactivate(Sender: TObject);
begin
  FrameForm.Caption:=SaveName;
end;

procedure TEditForm.FormResize(Sender: TObject);
begin
  if Self.WindowState=wsMaximized then
    FrameForm.Caption:=SaveName
  else
    FrameForm.Caption:=SaveName+' - ['+Caption+']';
end;

end.

PS: This code is only tested with Delphi 3.0 but should work on higher
version, too.

If that isn't it what you want or if you have any questions, email me: tds@schandog.de
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question