1 (edited by Step-in 2024-10-10 06:25:47)

Topic: [SOLVED]Inactive users on login form

Hello everyone. Maybe someone uses the standard login form and knows how to hide inactive users from the combobox?

Re: [SOLVED]Inactive users on login form

procedure frmLogin_OnActive;
var
  i: integer;
begin
  for i := 0 to frmdbCoreLogin.componentCount - 1 do
  begin
    if frmdbCoreLogin.Components[i] is TDBComboBox then
    begin
      TdbCombobox( frmdbCoreLogin.Components[i]).dbFilter := 'is_active=1';
      TdbCombobox( frmdbCoreLogin.Components[i]).dbUpdate;
      exit;
    end;
  end;
end;

begin
  frmdbcorelogin.OnActivate := @frmLogin_OnActive;
end.

Not fully tested in further work. But it seems like everything should work.

Re: [SOLVED]Inactive users on login form

Hi Step-In, Hi Sparrow,
You can also refer to the component directly (it's Component 6 on the standard "frmdbcorelogin" form) if you want to take a short-cut (which I always do - big_smile!). but Sparrow's example is obviously the proper way to do it.
Derek.

Post's attachments

Attachment icon active users only.zip 435.63 kb, 262 downloads since 2024-10-08 

Re: [SOLVED]Inactive users on login form

Thank you sparrow, derek for the quick reply. However, I think I missed an important point. My program uses a login replacement window from a related topic. I also have a project on MySQL

Part of my login window code

function GetCombo: TdbComboBox;
var
  i: integer;
begin
  for i := 0 to frmdbCoreLogin.componentCount - 1 do
  begin
    if frmdbCoreLogin.Components[i] is TdbCombobox then
    begin
      Result := TdbComboBox(frmdbCoreLogin.Components[i]);
      Result.dbFilter := 'is_active = 1';
      exit;
    end;
  end;
end;

procedure Login_OnClick( Sender:TObject; var Cancel:boolean );
var
  tmpMD5: string;
  tmpUsername: string;
    begin
  if frmdbCoreLogin.edLogin.Visible then
    tmpUsername := frmdbCoreLogin.edLogin.Text
  else
    tmpUsername := GetCombo.Text;
  tmpMD5 := StrToMD5( frmdbCoreLogin.edPassword.Text + tmpUserName );
  if SQLExecute('SELECT count(*) FROM _user WHERE username = "'+tmpUserName+'" AND password = "'+tmpMD5+'" ') = 0 then
    MessageBox('Invalid login or password','Error', MB_ICONWARNING + MB_OK )
  else
  begin
   SendMessage( frmdbCoreLogin.bLogin.handle , wm_LButtonDown, 0, 0);
   sleep(100);
   SendMessage( frmdbCoreLogin.bLogin.handle , wm_LButtonUp, 0, 0);
 end;
end;

procedure Init;
var
  tmpLoginButton: TdbButton;
begin
  tmpLoginButton := TdbButton.Create( frmdbCoreLogin );
  tmpLoginButton.Parent := frmdbCoreLogin;
  tmpLoginButton.Top := frmdbCoreLogin.bLogin.Top;
  tmpLoginButton.Left := frmdbCoreLogin.bLogin.Left;
  tmpLoginButton.Width := frmdbCoreLogin.bLogin.Width;
  tmpLoginButton.Height := frmdbCoreLogin.bLogin.Height;
  tmpLoginButton.Caption := 'Entry';
  tmpLoginButton.Font := frmdbCoreLogin.bLogin.Font;
  tmpLoginButton.Default := True;
  tmpLoginButton.OnClick := 'Login_OnClick';
  frmdbCoreLogin.bLogin.Visible := False;
end;

Re: [SOLVED]Inactive users on login form

Unfortunately, at such a distance, my psychic abilities are not enough to restore the full program from part of the code.
I see through the fog of distance that this is part of the user code k245.
As far as I remember, this is just localization of the login menu.
And the form is standard. And this code contains a ComboBox, and the _User table in MySql is the same as in SQLite.

Re: [SOLVED]Inactive users on login form

Hi Step-In, Sparrow,
As Sparrow writes, the code to limit the combobox to just 'active users' remains the same.whether you use the 'standard' login form without any amendments or whether you have personalised it (see attachment).
Derek.

Post's attachments

Attachment icon bespoke login form.zip 453.84 kb, 203 downloads since 2024-10-08 

Re: [SOLVED]Inactive users on login form

Thanks a lot for your help Sparrow & derek. Got it figured out. it's just that the data fill/filter function call must be done before the form translation code. Once again, thank you very much for your help.