Solved

trouble forms mdi child

Posted on 1998-11-11
3
222 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now