I have created a login window and a main window. The problem is that when I call the Close method in the successful login branch, the return value of ShowModal for the login form is always 2 (which I assume corresponds to mrCancel), even though I have explicitly set the ModalResult of the login form to mrOk.
From what I found online, the Close function automatically sets the ModalResult to 2. I'm not sure if this information is accurate. If it is, then what is the correct way to implement a login window?
I mean I need to close the login window and return a mrOk to the lpr, so the lpr will create the main window.
Thanks.
The login method:
...
if (edtUsername.Text = 'admin') and (edtPassword.Text = 'admin') then
begin
ShowMessage('OK');
self.ModalResult := mrOk; // Signal successful login
Close; // Close the login form, but it seems like this will change the modalresult.
end
else
...
In the lpr file, I have something like this:
loginResult := FLogin.ShowModal();
ShowMessage('Login Result ' + IntToStr(loginResult));
if (loginResult = mrOk) then
begin
Application.CreateForm(TFMain, FMain);
Application.Run;
end;