Jump to content

Warning: Form must be shown after is created: MainForm


Emiliano

Recommended Posts

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

 

post-948-0-21932100-1400730321_thumb.jpg

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Administrators

 

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.

Link to comment
Share on other sites

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. 
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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+

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...