I have setup my login procedure with an available form (Form4) and a MainForm. On the available form (form4) I have:
var
Form4: TForm4;
procedure Login;
implementation
.....
The 'Login' procedure goes:
procedure Login;
begin
with TForm4.Create(nil) do
try
Application.MainForm.Hide;
if ShowModal = mrOK then
Application.MainForm.Show
else
Application.Terminate;
finally
Free;
end;
end;
Then on the same form I have a button to log in :
procedure TForm4.AdvGlowButton1Click(Sender: TObject); //the buton's property is ModalResult=mrOK
begin
DataModule2.LOGIN_QUERY.Active:=false;
DataModule2.LOGIN_QUERY.SQL.Clear;
DataModule2.LOGIN_QUERY.SQL.Add('select user,passsword from users where user='+QuotedStr(cxlookupcombobox1.text)+' and password='+QuotedStr(cxTextEdit1.Text));
DataModule2.LOGIN_QUERY.Open;
if DataModule2.LOGIN_QUERY.FieldByName('password').AsString<>''
then ModalResult := mrOK else
ModalResult := mrNone;
end;
The project source goes like this :
begin
Application.Initialize;
Application.MainFormOnTaskbar := False;
Application.CreateForm(TDataModule2, DataModule2);
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TForm7, Form7);
Application.CreateForm(TARCHIVE, ARHCIVE);
Application.CreateForm(TForm10, Form10);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm6, Form6);
Application.CreateForm(TForm5, Form5);
Application.CreateForm(TForm9, Form9);
Application.CreateForm(TForm12, Form12);
Application.CreateForm(TForm12, Form12);
Application.CreateForm(TAboutBox, AboutBox);
Login;
Application.Run;
end.
Yet, every now and then when clicking the Login button on Form4 the application terminates without no reason. Why is this happening ? Should
Application.MainFormOnTaskbar := False;
be set to true perhaps?
Edit:
I edited the project file and the form4 on create event :
procedure TForm4.FormCreate(Sender: TObject);
begin
AdvGlowButton1.ModalResult := mrOK;
end;
and changed the project source :
{$R *.res}
var
MainForm: TMainForm;
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.MainFormOnTaskbar := False;
Application.CreateForm(TDataModule2, DataModule2);
Application.CreateForm(TForm7, Form7);
Application.CreateForm(TARCHIVE, ARCHIVE);
Application.CreateForm(TForm10, Form10);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm6, Form6);
Application.CreateForm(TForm5, Form5);
Application.CreateForm(TForm9, Form9);
Application.CreateForm(TForm12, Form12);
Application.CreateForm(TForm12, Form12);
Application.CreateForm(TAboutBox, AboutBox);
Login;
Application.Run;
end.
and I dont seem to be getting application closing....(it still does,ughh...)
edit2:
Tried this way. I set my AdvGlowButton1 to ModalResult=mrNone and the Form style to fsdialog:
procedure TForm4.AdvGlowButton1Click(Sender: TObject); //the buton's property is ModalResult=mrOK
begin
DataModule2.LOGIN_QUERY.Active:=false;
DataModule2.LOGIN_QUERY.SQL.Clear;
DataModule2.LOGIN_QUERY.SQL.Add('select user,passsword from users where user='+QuotedStr(cxlookupcombobox1.text)+' and password='+QuotedStr(cxTextEdit1.Text));
DataModule2.LOGIN_QUERY.Open;
if DataModule2.LOGIN_QUERY.FieldByName('password').AsString<>''
then ModalResult := mrOK else
dxStatusBar1.Panels[1].Text :='Wrong password !';
end;
this works most of the times and yet it sometimes closes when I start the application and hit the AdvGlowButton1 button (login button) . Another thing I figured out is missing, how do you prompt for the closure of the application on this login form as it expects only modal results?