sysjames Posted September 22, 2017 Share Posted September 22, 2017 I have a login screen that serves two purposes: To login OR to create a new account. The problem I have is in trying to present messages when the user enters incorrect information or tries to create an already existing account. I've tried several methods of presenting the messages (and perhaps giving them a second chance) without success. How do you do this? A picture of my login screen is attached. Quote Link to comment Share on other sites More sharing options...
herculanojs Posted September 22, 2017 Share Posted September 22, 2017 Can you post the code or part of the code that is trying to do this? Have already taken a look at the examples, specifically Dialogs Quote Link to comment Share on other sites More sharing options...
sysjames Posted September 22, 2017 Author Share Posted September 22, 2017 This was my last attempt: I had a panel called "MessageArea" with a label called "MessageText". I was putting the message text into MessageText and making MessageArea visible (It was not visible at the start). The trouble with this approach was that nothing stopped the loop (as a real dialog would). I also tried MessageDlg and even UniSF's SweetAlert, None of which worked (they did not display). (I am about to conclude that I should bypass the login screen altogether, main my own (Main) and use secondary created screens as to process the application. My current code follows: Procedure TUniLoginForm1.CancelBtnClick(Sender: TObject); Begin ModalResult := mrCancel; Close End; Procedure TUniLoginForm1.CreateBtnClick(Sender: TObject); Var CreateOK: Boolean; Begin CreateOK := False; While Not CreateOK Do Begin If (Email.Text <> '') And (Password.Text <> '') And (FName.Text <> '') And (LName.Text <> '') Then Begin Try UniMainModule.Account := CreateAccount(Email.Text, Password.Text, FName.Text, LName.Text, 0); ModalResult := mrOK; Close; Except On E: PlErrAcctAExist Do Begin MessageText.Text := 'That account already exists'; MessageArea.Visible := True; End; End; End; End; End; Procedure TUniLoginForm1.LoginBtnClick(Sender: TObject); Var LoginOK: Boolean; Begin LoginOK := False; While Not LoginOK Do Begin Try UniMainModule.Account := LoadAccount(EmailEntry.Text, PassEntry.Text); LoginOK := True; Except On E: PlErrAcctNF Do LoginOK := False; On E: PlErrBadPass Do LoginOK := False; End; If LoginOK Then Begin ModalResult := mrOK; Close; End Else Begin MessageText.Text := 'The account or the password is in error'; MessageArea.Visible := True; End; End; End; Procedure TUniLoginForm1.MessageCancelBtnClick(Sender: TObject); Begin ModalResult := mrCancel; Close; End; Procedure TUniLoginForm1.TryAgainBtnClick(Sender: TObject); Begin MessageArea.Visible := False End; Quote Link to comment Share on other sites More sharing options...
herculanojs Posted September 22, 2017 Share Posted September 22, 2017 I think I could try something like this: Procedure TUniLoginForm1.CreateBtnClick(Sender: TObject); Begin ModalResult := mrNone; If (Email.Text <> '') And (Password.Text <> '') And (FName.Text <> '') And (LName.Text <> '') Then Begin Try UniMainModule.Account := CreateAccount(Email.Text, Password.Text, FName.Text, LName.Text, 0); ModalResult := mrOK; Close; Except messagedlg('That account already exists',mtWarning,[mbOK]); End; End else messagedlg('...',mtWarning,[mbOK]); End; Procedure TUniLoginForm1.LoginBtnClick(Sender: TObject); Begin Try ModalResult := mrNone; UniMainModule.Account := LoadAccount(EmailEntry.Text, PassEntry.Text); ModalResult := mrOK; Close; Except messagedlg('The account or the password is in error',mtWarning,[mbOK]); End; End; Quote Link to comment Share on other sites More sharing options...
sysjames Posted September 22, 2017 Author Share Posted September 22, 2017 Thank you for your reply. However, my problem remains. In the code shown below, I still get to the MessageDlg line and the main program is invoked (which causes a problem, since the account object is used in the creation of the main form), the message isn't presented until the main form is created. Procedure TUniLoginForm1.LoginBtnClick(Sender: TObject); Begin ModalResult := mrNone; If AccountExtant(EmailEntry.Text, PassEntry.Text) Then Begin UniMainModule.Account := LoadAccount(EmailEntry.Text, PassEntry.Text); ModalResult := mrOK; Close; End Else messagedlg('The account or the password is in error', mtWarning, [mbOK]); End; Quote Link to comment Share on other sites More sharing options...
herculanojs Posted September 22, 2017 Share Posted September 22, 2017 Ok, I'll prepare an example here and already put it for you Quote Link to comment Share on other sites More sharing options...
herculanojs Posted September 22, 2017 Share Posted September 22, 2017 Follow example Project6.zip 1 Quote Link to comment Share on other sites More sharing options...
sysjames Posted September 23, 2017 Author Share Posted September 23, 2017 Thank you so much! The sample has really been helpful. Thanks again! Quote Link to comment Share on other sites More sharing options...
herculanojs Posted September 23, 2017 Share Posted September 23, 2017 cool Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.