CCH4UNIGUI Posted March 4, 2021 Share Posted March 4, 2021 Hi Farshad/Sherzod 1. Started new project 2. Added LoginForm via Unigui Wizard 3. Added UniEdit1: TUniEdit; 4. Declared cUserID: string as public 5. Input UniEdit1.Text=8180 in Login Form 5. cUserID:=trim(UniEdit1.Text) ; 6. Press OK to proceed to MainForm 7. ShowMessage( cUserID) in MainForm shows no value (expect to see 8180) Q. Why is public variable cUserID not visible in MainForm ? How can I make public variable cUserID visible in MainForm ? Actual Project Codes unit Login; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniButton, uniEdit, uniPanel, uniGUIBaseClasses, uniLabel, Data.DB, Data.Win.ADODB; type TUniLoginForm1 = class(TUniLoginForm) UniLabel1: TUniLabel; UniLabel2: TUniLabel; UniPanel1: TUniPanel; UniEdit1: TUniEdit; UniEdit2: TUniEdit; UniButton1: TUniButton; UniButton2: TUniButton; procedure UniButton1Click(Sender: TObject); procedure UniButton2Click(Sender: TObject); private { Private declarations } public { Public declarations } cUserID:string ; end; function UniLoginForm1: TUniLoginForm1; implementation {$R *.dfm} uses uniGUIVars, MainModule, uniGUIApplication, Main; function UniLoginForm1: TUniLoginForm1; begin Result := TUniLoginForm1(UniMainModule.GetFormInstance(TUniLoginForm1)); end; procedure TUniLoginForm1.UniButton1Click(Sender: TObject); begin cUserID:=trim(UniEdit1.Text) ; //showmessage(cUserID) ; ModalResult := mrOK; end; procedure TUniLoginForm1.UniButton2Click(Sender: TObject); begin ModalResult := mrCancel; end; initialization RegisterAppFormClass(TUniLoginForm1); unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniGUIBaseClasses, uniBasicGrid, uniDBGrid, Data.DB, Data.Win.ADODB; type TMainForm = class(TUniForm) UniDBGrid1: TUniDBGrid; EmployeeDS: TDataSource; EmployeeTable: TADODataSet; ADOConnection1: TADOConnection; procedure UniFormCreate(Sender: TObject); private { Private declarations } public { Public declarations } cUserID:string; end; function MainForm: TMainForm; implementation {$R *.dfm} uses uniGUIVars, MainModule, uniGUIApplication, Unit1, Login; function MainForm: TMainForm; begin Result := TMainForm(UniMainModule.GetFormInstance(TMainForm)); end; procedure TMainForm.UniFormCreate(Sender: TObject); begin EmployeeTable.Active:=False; showmessage(cUserid); //Blank value shown EmployeeTable.CommandText:='select * from employee where id=8180'; //EmployeeTable.CommandText:='select * from employee where id='+QuotedStr(cUserId); EmployeeTable.Active:=True; end; initialization RegisterAppFormClass(TMainForm); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 4, 2021 Share Posted March 4, 2021 Hello, In general, your approach is wrong... \FMSoft\Framework\uniGUI\Demos\Desktop\LoginForm http://unigui.com/doc/online_help/index.html?best-practices.htm Quote Link to comment Share on other sites More sharing options...
Ron Posted March 4, 2021 Share Posted March 4, 2021 You should do all the user credentials checking in the login form, so when you close the login form the user is considered authorized and logged in. SO there are two ways out of the login form, and you determine that before you leave the form: modalResult:=mrOK - user is logged in modalResult:=mrCancel - user failed authorization Quote Link to comment Share on other sites More sharing options...
CCH4UNIGUI Posted March 5, 2021 Author Share Posted March 5, 2021 54 minutes ago, Ron said: You should do all the user credentials checking in the login form, so when you close the login form the user is considered authorized and logged in. SO there are two ways out of the login form, and you determine that before you leave the form: modalResult:=mrOK - user is logged in modalResult:=mrCancel - user failed authorization Hi Ron I understand the concept as above but what I want to do is simple. Once logged in, I want to use the User ID to be used to filter to only show data belonging to the logged in UserId. How do I do that ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 5, 2021 Share Posted March 5, 2021 2 minutes ago, CCH4UNIGUI said: I understand the concept as above but what I want to do is simple. Once logged in, I want to use the User ID to be used to filter to only show data belonging to the logged in UserId. How do I do that ? 17 hours ago, Sherzod said: \FMSoft\Framework\uniGUI\Demos\Desktop\LoginForm Use UniMainModule... procedure TUniLoginForm1.UniButton1Click(Sender: TObject); begin UniMainModule.AUserName := 'This User'; UniMainModule.AUserID := 777; ModalResult:=mrOK; // Login is valid so proceed to MainForm end; Quote Link to comment Share on other sites More sharing options...
CCH4UNIGUI Posted March 5, 2021 Author Share Posted March 5, 2021 2 hours ago, Sherzod said: Hello, In general, your approach is wrong... \FMSoft\Framework\uniGUI\Demos\Desktop\LoginForm http://unigui.com/doc/online_help/index.html?best-practices.htm Hi Sherzod I understand the concept in the LoginForm but what I want to do is simple. Once logged in, I want to use the User ID to be used to filter to only show data belonging to the logged in UserId. How do I do that ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 5, 2021 Share Posted March 5, 2021 Quote Link to comment Share on other sites More sharing options...
CCH4UNIGUI Posted March 5, 2021 Author Share Posted March 5, 2021 TQ. Have used a TUnilabel.caption on MainForm to verify the cUserId input. Quote Link to comment Share on other sites More sharing options...
Ron Posted March 10, 2021 Share Posted March 10, 2021 Whatever data you need after login, you can store in the mainmodule as variables. So in the LoginForm, you just set those variables before closing the form, and then check those variables again as the mainform opens, doing whatever you want to do. 1. Declare the var in mainModule. 2. Set the var in loginForm, before close 3. Read the var in mainForm, at onShow or later Quote Link to comment Share on other sites More sharing options...
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.