Jump to content

Can you have 2 MainForm's?


Petzy

Recommended Posts

Can we have 2 MainForm's and just use one based on some user settings?

 

For example:

 

I use a UniLoginForm to authenticate the user.

On clicking the LoginButton present on UniLoginForm an sql query fires up logging him (UniLoginForm modalresult mrOk) in based on database details - typical Login system.

 

Invariably that pops up the MainForm already present in the Project/at project creation.

 

I was thinking, could I possibly add a new UniForm and use that as the MainForm based on an existing condition?

 

For example in the database the username has a field called admin, the field can contain yes or no.

On the previously mentioned LoginButton present on UniLoginForm1 I can add a check for that field value and if it returns no for that user then the existing MainForm should be used, as a MainForm.

 

If on the other hand the field value returns yes for that user then it should use the other MainForm.

 

Reason I want to do this is because I'm trying to separate regular users from admin users - subsequently providing different functionality, design, components and so on, on their respective MainForm's.

 

Is this doable? If not, could you recommend any other method to achieve this?

 

I'd appreciate some input on the matter. I'm currently in the process of re-reading the unigui devmanual and component manual to determine if this is achievable. Thanks!

Link to comment
Share on other sites

Hi! I do it in my app in that way:

in the real main form do check, does the user have admin priveleges, and if no, I hide this form and show other one, user's, form:

procedure TForm1.UniFormShow(Sender: TObject);
begin
 if Users.IsPermitted(UniMainModule.LoggedUserHash, 'CAN_ADMIN') then
  NeedSetMainForm := True
 else
 begin
  Hide;
  UniForm14.Show;
 end;
end;

as I know, all works fine.

Link to comment
Share on other sites

 

Hi! I do it in my app in that way:

in the real main form do check, does the user have admin priveleges, and if no, I hide this form and show other one, user's, form:

procedure TForm1.UniFormShow(Sender: TObject);
begin
 if Users.IsPermitted(UniMainModule.LoggedUserHash, 'CAN_ADMIN') then
  NeedSetMainForm := True
 else
 begin
  Hide;
  UniForm14.Show;
 end;
end;

as I know, all works fine.

 

 

Hi, thanks for the code and idea.

 

Could you clarify your code further?

 

As I understand it - your other "MainForm" - the not admin user is called UniForm14

Your actual MainForm, the one admin's use, is called Form1

 

What is "NeedSetMainForm" defined as?

What is "Users" (Users.IsPermitted) defined as?

 

I'm guessing UniMainModule.LoggedUserHash is a string variable?

 

Where have you chosen to do the check in the real main form?

 

Appreciate it

Link to comment
Share on other sites

TForm1 is the main form of my app and admin's main form.

UniForm14 is the user's main form.

NeedSetMainForm is the flag for timer of the TForm1. Timer do some setup of the main form after start.

Users is internal class of all user's data.

UniMainModule.LoggedUserHash is the hash of current logged user.

Link to comment
Share on other sites

Thanks for the help Tokay, implemented successfully and it works like a charm!

 

I'll come back with a demo attachment after I finish the project - just so anyone reading in the future and needing this can have a working example.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...