How do I run the Menuiten.Click event in an if? Delphi loop

Asked

Viewed 565 times

0

I’m putting together the login part of my system, only I’m facing a big problem. My cancel button from the login screen needs to receive two features. The first is that being clicked before the main screen of the system is opened the entire application is terminated. If the main screen is already open it is to make the second functionality that would cancel the user change at runtime ! That is, the logout cancellation, the user exchange canceled. However for the logic I am using to work, it has to be passed by an if, only the logout click is an Itemmenu of a Mainmenu. If I wear it like this

if FrmPrincipal.Logout1.Click = True then

It accuses error of incompatible type If I’ve done it this other way

if FrmPrincipal.Logout1.OnClick

He’s wrong and he doesn’t turn. That’s what I wanted to know... how do I make an Itemmenu run in an if loop.

1 answer

1

If I were you, I would control with a private variable feeding in the main onCreate, so it would open Login and in the Login onCreate feed the variable with False, in the main onShow I check if it is to login or not, looking at the variable. As follows:

onCreate Leading:

bLogin := False;
fmLogin := TfmLogin.Create(Self); 
try
  fmLogin.ShowModal;
  bLogin := fmLogin.OKLogin;
finally
   FreeAndNil(fmLogin);
end;

onCreate Login:

bOKLogin := False

onShow Leading:

if bLogin then
begin
  ...
end
else
begin
  Application.Terminate;
end;

But starting from your logic, you can call the Onclick event from Logout not needing to check whether or not clicked.

   FrmPrincipal.Logout1.OnClick(Sender)

You can also control with a Checked in Menuitem, Menuitem has a property with Autocheck, marking this property he will control the check in the menuItem, so you can check whether it is checked or not at the time he clicks on the menuitem.

 if testecheck.Checked then
     ShowMessage('teste');
  • This code you gave me continued giving the same error. Then the Login screen call it in the onCreate of the Main. I couldn’t quite understand what you said in the part about onShow.

  • @Alisonpaulo, if you call the Login screen in the main onCreate, with a showmodal, it will be waiting for the return of the Login screen, because it is a Showmodal, in the onCreate of Login you could put a private variable as false, if it closes the login screen, will go back to the screen of the main onCreate you could feed in a variable the return of Login. Right after the Oncreate of the Main it falls in onShow, in this part you check if it is to login or not. I do not know if I was clear.

  • Interesting had not thought this way, I will implement now, let me just ask one thing, what would be Oklogin a variable? Excuse the question but I am junior programmer learning yet hehe. the variable blogin would be type tform?

  • The two variables are of the type Boolean, one you declare in the main and the other in the Login, when you enter the onCrete of the Login you already declare it as False, because if you leave the screen of the Login it is already false, then no event will happen and when you return to the Main onCreate you feed the boolean variable of the main with the boolean variable of Login.

  • @Alisonpaulo, did you manage to solve the problem?... if you could mark the answer to help the other members of the forum.

  • So, by what I tested depending on how it is developing works yes, for me it did not work because it will directly influence the restrictions of logged in users. As it has a Free it will clear all user information logged in. And the restrictions have connection with the id of the logged in user, giving that freeandnil cleans the id there the system is without restrictions, but for what I tested it would work yes, for me unfortunately it did not, but I really appreciate your help, thanks to this I found a new logic for login in systems Delphi.

  • @Alisonpaulo has decided for you, has how to mark the answer, so serves for other users. Thank you

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.