Solved

trouble forms mdi child

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Internet Explorer View Settings Question 15 116
Base1 Encode/Decode 3 81
firemonkey keyboard covers the controls 1 37
Microsoft Access 97 and Delphi XE2 9 54
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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