Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2012, 10:55 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default Load forms as required.

Normally Delphi loads all the forms at runtime.

How do load forms only as needed ?

Eg

Form1 Connect to database
if Connected then load Form2

If I load form2 at the start, it tries to get data from a database that has not been opened as yet and crashes.

Thanks Wallace
Reply With Quote
  #2  
Old 06-25-2012, 08:00 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 6,699
Default

In the project manager right click on your project and select "view source"

Here you can remove all forms you don't want created, or change the order in which they do get created...
Now you can be as creative as you want with the rest (loading/creating the other forms)...

FYI: a form shouldn't connect to a database, a datamodule should
Reply With Quote
  #3  
Old 06-25-2012, 09:19 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

I need a form to be able to enter username and password.

Only the SQl connector is on the login form. All the tables are in the DM.

This is what I have - Probably not the best but Rome was not built in a day.

Code:
program Register;

uses
  Forms,
  uLogin in 'uLogin.pas' {fLogin},
  uDM in 'uDM.pas' {dm: TDataModule},
  uMain in 'uMain.pas' {fMain},
  uBikes in 'uBikes.pas' {fBikes},
  ... 
  uPrnMembers in 'uPrnMembers.pas' {fPrnMembers};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TfLogin, fLogin);
  Application.CreateForm(Tdm, dm);
  Application.Run;
end.
on fLogin

Code:
procedure TfLogin.ConnectClick(Sender: TObject);
begin
   with MyRegister do begin
      Connected:=False;
      Port:=StrToInt(ePort.Text);
      Server:=eServer.Text;
      Username:=eUsername.Text;
      Database:=eDataBase.Text;
      Password:=ePassword.Text;
      try
        Connected:=True;
etc
Code:
procedure TfLogin.MyRegisterAfterConnect(Sender: TObject);
begin
   dm.tblEvent.Active:=True;
   dm.tblMembers.Active:=True;
   ......

   Application.CreateForm(TfMain, fMain);
   Application.CreateForm(TfBikes, fBikes);
   ..............
   fMain.Show;
end;
Messy but I'm a willing learner. How do I improve it ?
Reply With Quote
  #4  
Old 06-25-2012, 09:22 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 6,699
Default

Code:
program Register;

uses
  Forms,
  uLogin in 'uLogin.pas' {fLogin},
  uDM in 'uDM.pas' {dm: TDataModule},
  uMain in 'uMain.pas' {fMain},
  uBikes in 'uBikes.pas' {fBikes},
  ... 
  uPrnMembers in 'uPrnMembers.pas' {fPrnMembers};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(Tdm, dm);
  Application.CreateForm(TfLogin, fLogin);
  if dm.MyRegister.Connected then
    Application.Run;
end.
And in the fLogin call the dm.MyRegister component instead...
NB: Note that I also changed the creation order
Reply With Quote
  #5  
Old 06-25-2012, 10:00 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

Thanks I'll try your ideas tomorrow. It's late here in New Zealand. Cheers
Reply With Quote
  #6  
Old 06-25-2012, 01:34 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 648
Default

Hi

You should read this page top to bottom, if you don't, you will mess up.

Get an new project and play with it, very simple and very useful

http://delphi.about.com/od/beginners/l/aa070203c.htm

Hope it helps

Good luck

Regards
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:08 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.