![]() |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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.
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; |
|
#4
|
|||
|
|||
|
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.
NB: Note that I also changed the creation order |
|
#5
|
|||
|
|||
|
Thanks I'll try your ideas tomorrow. It's late here in New Zealand. Cheers
|
|
#6
|
|||
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|