Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI Form, Login Screen 2

Status
Not open for further replies.

browneye

Programmer
Nov 21, 2000
82
US
Hello,
I am Totally New to Delphi. I am using Delphi 7. I am trying to create small MDI application which have frmMDI as MDI form ,Form2 as MDI Child Form,Form3 as Login form (Normal Form). First Login form should be displayed . Right Now I have only one command button on login form. When I click that button it should Open MDI Form. MDI Form has Open menu .When I click open menu Form2 should be displayed. I got working everything except Login form. It works fine without login form. But when I try to add login form it wont work..Any Idea?

Thank you in advance.
 
in your project settings set what forms you want created at program start up.

the way i would do it is have the logon form as autocreate only.
then create the mdiform from the logon form when logon is succesfull else terminate the app.

to create the mdi form would be something like this
(i think)

if frmMDI = null then
frmMDI:=frmMDI.create(application);

Aaron Taylor
John Mutch Electronics
 
Hi Aaron,
Thank you for your reply.I really appriciate it. I am still getting an error Incompatible Types Unit3.pas(30)
Here is code.
My project options are
Main form=Form3
AutoCreate Forms=Form3
Avaliable Forms=frmMDI & Form2

Project1.dpr
============
program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {frmMDI},
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas' {Form3};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm3, Form3);
Application.Run;
end.

UNIT1.dfm
==========
object frmMDI: TfrmMDI
Left = 205
Top = 177
Width = 870
Height = 500
Caption = 'frmMDI'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIForm
Menu = MainMenu1
OldCreateOrder = False
OnActivate = FormActivate
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 424
Top = 240
object File1: TMenuItem
Caption = 'File'
object New1: TMenuItem
Caption = 'New'
OnClick = New1Click
end
object Exit1: TMenuItem
Caption = 'Exit'
OnClick = Exit1Click
end
end
end
object MainMenu2: TMainMenu
Left = 432
Top = 248
object File2: TMenuItem
Caption = 'File'
object Open1: TMenuItem
Caption = 'Open'
end
object Exit2: TMenuItem
Caption = 'Exit'
end
end
end
end

UNIT2.dmf
==========
object Form2: TForm2
Left = 655
Top = 403
Width = 530
Height = 317
Caption = 'frmChild'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIChild
OldCreateOrder = False
Position = poDefault
Visible = True
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 272
Top = 88
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Memo1: TMemo
Left = 16
Top = 152
Width = 185
Height = 89
Lines.Strings = (
'Memo1')
TabOrder = 1
end
object Button1: TButton
Left = 232
Top = 144
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 2
OnClick = Button1Click
end
end

UNIT3.dfm
=========
object Form3: TForm3
Left = 270
Top = 187
Width = 546
Height = 343
Caption = 'frmLogin'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 240
Top = 160
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end


UNIT1.pas
=========
unit Unit1;

interface

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

type
TfrmMDI = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
New1: TMenuItem;
Exit1: TMenuItem;
MainMenu2: TMainMenu;
File2: TMenuItem;
Open1: TMenuItem;
Exit2: TMenuItem;
procedure Exit1Click(Sender: TObject);
procedure New1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmMDI: TfrmMDI;

implementation

uses Unit2, Unit3;

{$R *.dfm}

procedure TfrmMDI.Exit1Click(Sender: TObject);
begin
close;
end;

procedure TfrmMDI.New1Click(Sender: TObject);
var Child : TForm2;
begin
child := Tform2.Create(self);
child.Show;
end;

procedure TfrmMDI.FormCreate(Sender: TObject);
begin
form3.showmodal;
end;

procedure TfrmMDI.FormActivate(Sender: TObject);
begin
unit3.Form3.showmodal;
end;

end.

UNIT2.pas
=========
unit Unit2;

interface

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

type
TForm2 = class(TForm)
Edit1: TEdit;
Memo1: TMemo;
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
//TCloseEvent = procedure Button1Click(Sender: TObject);
//TCloseAction = (caNone, caHide, caFree, caMinimize);
//TCloseEvent = procedure (Sender: TObject; Var Action : TCloseAction);
//property OnClose:TCloseEvent
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation



{$R *.dfm}


procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action := cafree
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
//TForm2.FormClose(self);
end;

end.
UNIT3.pas
=========
unit Unit3;

interface

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

type
TForm3 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
if frmmdi = null then frmmdi:= unit1.TfrmMDI.Create(application);
close;
end;

end.


Again I appriciate your help. Thank you very much.

Have A Great Day!!

--Nick
 
Try the following:

Code:
program Mdiapp;

uses

  Forms,
  Controls,
  MAIN in 'MAIN.PAS' {MainForm},
  CHILDWIN in 'CHILDWIN.PAS' {MDIChild},
  about in 'about.pas' {AboutBox},
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
  Application.CreateForm(TMainForm, MainForm);
  Application.CreateForm(TAboutBox, AboutBox);
  Application.CreateForm(TForm1, Form1);
  Form1.ShowModal;
  if form1.ModalResult = mrOk then
  begin
    form1.Close;
    Application.Run
  end
end.

I used the wizard to create an MDI Application, added Form1 (ie a log on form) with two buttons (Cancel and OK)

Cancel:
Default = False
ModalResult = mrCancel

OK:
Default = True
ModalResult = mrOK


When run, the program displays Form1 - click Cancel and the program closes, click OK and thelogon form closes and the MDI Form opens.


Hope this helps.




[vampire][bat]
 
Hi earthandfire,
I am trying to avoid using wizard because it give me lots of things i dont want to use.Like.. I want to use my custom control for mainmenu,toolbars stuff like that. One more thing wizard offers is creating MDIChild forms runtime. I am trying to develop database application where I have forms available just want to show them as needed. I dont want to create runtime forms.
Thanks for ur response..If you can email me code.that would be great because Since long time i have been working in VB..Im totally new here..dont know lot of stuff..:)

Thank you

Have Great Day!!
 
Forget about the wizard, I just used that to quickly create an MDI Application - (me being lazy)

Just replace the code I've marked in bold with your own Unit/Form names

by the way TT Management get very upset by posters asking for email communication - this thread could be removed as a result

Code:
program Mdiapp;

uses

  Forms,
  Controls,
[b]  MAIN in 'MAIN.PAS' {MainForm},
  CHILDWIN in 'CHILDWIN.PAS' {MDIChild},
  about in 'about.pas' {AboutBox},
  Unit1 in 'Unit1.pas' {Form1}[/b];

{$R *.RES}

begin
[b]  Application.CreateForm(TMainForm, MainForm);
  Application.CreateForm(TAboutBox, AboutBox);
  Application.CreateForm(TForm1, Form1)[/b];
  Form1.ShowModal; //Your log on form I think you called it Form3
  if form1.ModalResult = mrOk then
  begin
    form1.Close;
    Application.Run
  end
end.

Hope this explains things better.

[vampire][bat]
 
Hi earthandfire,
Hey It worked !! Thank you for you help. I really appriciate it :) I liked delphi I wish I could have start working on it before!!
 
Unfortunately I'm working almost exclusively in VB.NET these days, from choice though I will always use Delphi and do so when I can. However since bills have to be paid, I have to work (most of the time) in the language of choice for my employer.

[vampire][bat]
 
I hear you ..Try to check out Delphi 2005 when you get chance..I am trying to check it out too..seems lot like dot net..Good luck :)

Thank you for your help. Appriciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top