Emiliano Posted May 22, 2014 Posted May 22, 2014 Hi I´m trying to develop a login form form a sample project After i click the "Ok" button in the login form, i receive this message: Warning: Form must be shown after is created: MainForm the Ok button code is: procedure TformLogin.UniButton1Click(Sender: TObject); var LoginString : string; begin LoginString := 'SELECT * FROM tbluser '; LoginString := LoginString + 'WHERE login = ' + #39 + (edtLogin.Text) + #39; LoginString := LoginString + ' AND password = ' + #39 + (edtPassword.Text) + #39; MainForm.qryLogin.Close; MainForm.qryLogin.SQL.Clear; MainForm.qryLogin.SQL.Add(LoginString); MainForm.qryLogin.open; if not MainForm.qryLogin.IsEmpty then // check if query is empty Begin if MainForm.qryLogin.FieldByName('status').AsString='0' then // check the user status, user may be inactive (0-inactive, 1-active) begin showmessage('User inactive'); // inform the user status MainForm.Close; // close the application end else begin ModalResult:=mrOK; Mainform.ShowModal(); MainForm.UniStatusBar1.Panels[1].Text := 'User:' + formLogin.edtLogin.Text; // write user name in status bar end; end else begin showmessage('Login or password is not correct!'); edtLogin.Text := ''; edtPassword.text := ''; edtLogin.SetFocus; ModalResult := mrNone; end; end; any suggestion on how to solve this error message would be fine thanks Quote
Administrators Farshad Mohajeri Posted May 22, 2014 Administrators Posted May 22, 2014 Login form should not reference main form. Main form is automatically shown when you close login form with modalresult mrOK. Included demos clearly demonstrate this. Quote
Emiliano Posted May 23, 2014 Author Posted May 23, 2014 Login form should not reference main form. Main form is automatically shown when you close login form with modalresult mrOK. Included demos clearly demonstrate this. Hi Farshad, I got from the demo directory this code: if sameText(edtLogin.Text, 'DEMO') and sameText(edtPassword.Text, 'DEMO') then begin if UniCheckBox1.Checked then begin UniApplication.Cookies.SetCookie('_loginname', edtLogin.Text, Date + 7.0); // Expires 7 days from now UniApplication.Cookies.SetCookie('_pwd', edtPassword.Text, Date + 7.0); end; ModalResult := mrOK; end; i included it, in the login button in loginform. 1. How to pass the text from both edits from loginform to mainform? 2. In the main form should i use UniApplication.Cookies.SetCookie? Thanks Emiliano Quote
Administrators Farshad Mohajeri Posted May 23, 2014 Administrators Posted May 23, 2014 Hi Farshad, I got from the demo directory this code: if sameText(edtLogin.Text, 'DEMO') and sameText(edtPassword.Text, 'DEMO') then begin if UniCheckBox1.Checked then begin UniApplication.Cookies.SetCookie('_loginname', edtLogin.Text, Date + 7.0); // Expires 7 days from now UniApplication.Cookies.SetCookie('_pwd', edtPassword.Text, Date + 7.0); end; ModalResult := mrOK; end; i included it, in the login button in loginform. 1. How to pass the text from both edits from loginform to mainform? 2. In the main form should i use UniApplication.Cookies.SetCookie? Thanks Emiliano 1. Pass them through public variables in MainModule or a DataModule. 2. It depends on you. We use cookies here only to save login info on client side. Quote
Jancarlos Martins Posted May 23, 2014 Posted May 23, 2014 Tudo bem Emiliano, O Farshad implementou uma nova classe para isso TUniLoginForm, olha no seu demos LoginFormm, e muito facil. Até mais.. Hi Emiliano, The Farshad implemented a new class for this TUniLoginForm looks on your demos LoginForm ,is very easy. Quote
Emiliano Posted May 23, 2014 Author Posted May 23, 2014 Tudo bem Emiliano, O Farshad implementou uma nova classe para isso TUniLoginForm, olha no seu demos LoginFormm, e muito facil. Até mais.. Hi Emiliano, The Farshad implemented a new class for this TUniLoginForm looks on your demos LoginForm ,is very easy. Oi perjanbr Vc tem algum exemplo sobre isso que possa me passar? Necessito manda pra tela principal dados que vem da tela de login, em um dos exemplos que ele estava usando cookie, só tem dessa forma? att Emiliano Quote
Emiliano Posted May 26, 2014 Author Posted May 26, 2014 1. Pass them through public variables in MainModule or a DataModule. 2. It depends on you. We use cookies here only to save login info on client side. Hi Farshad The login demo project with zeos and mysql is now working fine. May i send it to? So you could avaliate it, and maybe incluide in the demo folder. What do you think about it. Thanks Emiliano Quote
Administrators Farshad Mohajeri Posted May 26, 2014 Administrators Posted May 26, 2014 Thanks. We can't publish demos which are based on MySQL and 3rd party DB components. Our demos must be able to run on a fresh Delphi installation. You can post it to Sample Projects forum. Quote
Jancarlos Martins Posted May 26, 2014 Posted May 26, 2014 Isso e muito fácil. Lembre-se que o MainModule é aberto por sessão e ServerModule pela Aplicação, coloque qualquer tipo de dados na MainModule que só uma sessão vai ver ela. A unica coisa que seu formulário de login precisar fazer e ModalResult:=Mrok ou ModalResult:=MrCancel, no exemplo abaixo eu tenho uma função checkLogin que esta na MainModule , que chamo dentro do LoginForm, se retornar True os dados do usuário já ficam no MainModule. OK???, se mesmo assim você não conseguir faço um exemplo e envio em pvt. TUniMainModule = class(TUniGUIMainModule) private public usuarioPadrao:integer; razaoUsuario:String; ipConexao:String; function checkLogin(Codigo:String;Usuario:string;senha:String):boolean; end; t+ Quote
Oliver Morsch Posted May 26, 2014 Posted May 26, 2014 LoginString := 'SELECT * FROM tbluser '; LoginString := LoginString + 'WHERE login = ' + #39 + (edtLogin.Text) + #39; LoginString := LoginString + ' AND password = ' + #39 + (edtPassword.Text) + #39; And the password is: ' or '1'='1 see here 1 Quote
chefdackel Posted May 27, 2014 Posted May 27, 2014 Hi Farshad The login demo project with zeos and mysql is now working fine. May i send it to? So you could avaliate it, and maybe incluide in the demo folder. What do you think about it. Thanks Emiliano Post it in the "Sample Projects" part of this forum, please. Maybe interesting for other developers. Quote
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.