Solved

trouble forms mdi child

Posted on 1998-11-11
3
232 Views
Last Modified: 2010-04-04
i got an aplication, and it got MDI parent and children, my question is, how can i call into the MDI parent a child form
i've us  Tform.create(self) but it doesn't work.
later, how can i close them(children forms).
   
0
Comment
Question by:jabita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1346617
Here is an example...

Let's say you have a menu where you have an item New to create a new form...Here is how this is coded...

TForm1 is the MDI Child form's name...

with TForm1.Create(self) do
try
  //Maybe some properties or something...
  ShowModal;
finally
  Free;
end;

Hope this helps.
Cheers,
Viktor
0
 

Author Comment

by:jabita
ID: 1346618
i have use it but doesn't work
when i use run by step it collapse in the instruction TForm1.Create(self), and i dont know why, the compiler just give the direcctions.
 
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346619
Hello again!

Here is a whole project I got together for you....It contains two units ./// a Child.pas and Frame.pas .... The Child.pas is the unit that actually containts the Child Form.... Take a look at them...

//------------------- Frame.pas -------------------//
unit Frame;
interface
uses Windows, Classes, Graphics, Forms, Controls, Child,
  Menus, SysUtils;
type
  TMainForm = class(TForm)
    MainMenu1: TMainMenu;
    Window1: TMenuItem;
    New1: TMenuItem;
    File1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    Cascade1: TMenuItem;
    Tile1: TMenuItem;
    ArrangeIcons1: TMenuItem;
    procedure New1Click(Sender: TObject);
    procedure Cascade1Click(Sender: TObject);
    procedure Tile1Click(Sender: TObject);
    procedure ArrangeIcons1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
  private
    { Private declarations }
    Counter: Integer;
  public
    { Public declarations }
  end;
var
  MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.New1Click(Sender: TObject);
var
  ChildForm: TChildForm;
begin
  Inc (Counter);
  ChildForm := TChildForm.Create (self);
  ChildForm.Caption := ChildForm.Caption + ' ' +
    IntToStr (Counter);
  ChildForm.Show;
end;
procedure TMainForm.Cascade1Click(Sender: TObject);
begin
  Cascade;
end;
procedure TMainForm.Tile1Click(Sender: TObject);
begin
  Tile;
end;
procedure TMainForm.ArrangeIcons1Click(Sender: TObject);
begin
  ArrangeIcons;
end;
procedure TMainForm.Exit1Click(Sender: TObject);
begin
  Close;
end;
end.
//------------------- Child.pas -------------------//
unit Child;
interface
uses
  Windows, Classes, Graphics, Forms,
  Controls, Menus, Dialogs, SysUtils;
type
  TChildForm = class(TForm)
    MainMenu1: TMainMenu;
    Circle1: TMenuItem;
    FillColor1: TMenuItem;
    BorderColor1: TMenuItem;
    BorderSize1: TMenuItem;
    N1: TMenuItem;
    GetPosition1: TMenuItem;
    ColorDialog1: TColorDialog;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FillColor1Click(Sender: TObject);
    procedure BorderColor1Click(Sender: TObject);
    procedure BorderSize1Click(Sender: TObject);
    procedure GetPosition1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    XCenter, YCenter: Integer;
    BorderSize: Integer;
    BorderColor, FillCOlor: TColor;
  public
    { Public declarations }
  end;
var
  ChildForm: TChildForm;
implementation
{$R *.DFM}
procedure TChildForm.FormCreate(Sender: TObject);
begin
  XCenter := - 200;
  YCenter := - 200;
  BorderSize := 1;
  BorderColor := clBlack;
  FillColor := clYellow;
end;
procedure TChildForm.FormPaint(Sender: TObject);
begin
  Canvas.Pen.Width := BorderSize;
  Canvas.Pen.Color := BorderColor;
  Canvas.Brush.Color := FillColor;
  Canvas.Ellipse (XCenter-30, YCenter-30, XCenter+30, YCenter+30);
end;
procedure TChildForm.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  XCenter := X;
  YCenter := Y;
  Repaint;
end;
procedure TChildForm.FillColor1Click(Sender: TObject);
begin
  ColorDialog1.Color := FillColor;
  if ColorDialog1.Execute then
  begin
    FillColor := ColorDialog1.Color;
    Repaint;
  end;
end;
procedure TChildForm.BorderColor1Click(Sender: TObject);
begin
  ColorDialog1.Color := BorderColor;
  if ColorDialog1.Execute then
  begin
    BorderColor := ColorDialog1.Color;
    Repaint;
  end;
end;
procedure TChildForm.BorderSize1Click(Sender: TObject);
var
  InputString: string;
begin
  InputString := IntToStr (BorderSize);
  if InputQuery ('Border', 'Insert width', InputString) then
  begin
    BorderSize := StrToIntDef (InputString, BorderSize);
    Repaint;
  end;
end;
procedure TChildForm.GetPosition1Click(Sender: TObject);
begin
  MessageDlg ('The center of the circle is in the position (' +
    IntToStr (XCenter) + ', ' + IntToStr (YCenter) + ').',
    mtInformation, [mbOk], 0);
end;
procedure TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;
end.

Hope this helps you!

If you still need some help just say so :)

Cheers,
Viktor
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 132
Print Graphic and Text to Epson TM-T88v 12 544
Firemonkey android show image from resource ? 1 71
Firemonkey BASS_Init into a thread 17 79
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…

739 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