www.pudn.com > EmailServer.zip > ChooseUser.pas
unit ChooseUser;
(******************************************************************************)
(* *)
(* Hermes Choose User Dialog Box *)
(* Part of Hermes SMTP/POP3 Server. *)
(* Copyright(C) 2000 by Alexander J. Fanti, All Rights Reserver Worldwide. *)
(* *)
(* Created January 14, 2000 by Alexander J. Fanti. See License.txt *)
(* *)
(* Used by: AddEditMailList *)
(* Uses: DataU1 *)
(* *)
(* Description: This Modal dialog window lists mail users and domains the *)
(* server knows about. It's useful when we need to choose *)
(* either a user name (mailbox) or complete user e-mail address *)
(* for something, like adding a member to a mailing list. *)
(* *)
(* Revisions: 1/21/2000 AJF Commented *)
(* *)
(******************************************************************************)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;
type
TfrmChooseUser = class(TForm)
lstUsers: TListBox;
Panel1: TPanel;
btnOK: TBitBtn;
btnCancel: TBitBtn;
lstDomain: TComboBox;
procedure FormShow(Sender: TObject);
procedure lstUsersDblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
// if the user cancels, the return value from either of these functions
// will be '', remember to check for this when using these functions.
function SelectUser : String; // ShowModal and return selected user
function SelectUsers : Boolean;
function SelectAddress : String; // ShowModal and return selected address
function SelectAddresses : Boolean;
end;
var
frmChooseUser: TfrmChooseUser;
implementation
uses DataU1;
{$R *.DFM}
procedure TfrmChooseUser.FormShow(Sender: TObject);
var
x : Longint;
begin
// Fill the ListBox with the user names
lstUsers.Clear;
INI.User_GetList(lstUsers.Items);
// clear the domain list and fill it with the server's domains
lstDomain.Clear;
lstDomain.Items.Add(INI.ServerName);
for x := 0 to INI.Smtp_Domains.Count -1 do
lstDomain.Items.Add(INI.Smtp_Domains[x]);
// Select the first one (if available)
if lstDomain.Items.Count > 0 then lstDomain.ItemIndex := 0;
lstUsers.SetFocus;
end;
function TfrmChooseUser.SelectUser : String;
begin
// Hide the domain list (we just want a user)
lstDomain.Visible := False;
// ShowModal and get the user's choice
if (ShowModal = mrOK) and (lstUsers.ItemIndex > -1) then
Result := Trim(lstUsers.Items[lstUsers.ItemIndex])
else Result := '';
end;
function TfrmChooseUser.SelectUsers : Boolean;
begin
// Hide the domain list (we just want a user)
lstDomain.Visible := False;
lstUsers.MultiSelect := True;
// ShowModal and get the user's choice
Result := (ShowModal = mrOK) and (lstUsers.SelCount > 0);
end;
function TfrmChooseUser.SelectAddress : String;
var
Domain : String;
begin
// Show the domain list, we want to apply a domain to whatever is choosen
lstDomain.Visible := True;
// ShowModal and get the user's choice
if (ShowModal = mrOK) and (lstUsers.ItemIndex > -1) then begin
Domain := lstDomain.Items[lstDomain.ItemIndex];
Result := Trim(lstUsers.Items[lstUsers.ItemIndex]) + '@' + Domain;
end else Result := '';
end;
function TfrmChooseUser.SelectAddresses : Boolean;
var
Domain : String;
begin
// Show the domain list, we want to apply a domain to whatever is choosen
lstDomain.Visible := True;
lstUsers.MultiSelect := True;
// ShowModal and get the user's choice
Result := (ShowModal = mrOK) and (lstUsers.SelCount > 0);
end;
procedure TfrmChooseUser.lstUsersDblClick(Sender: TObject);
begin
// if they double-click a list item, that's the same as clicking "OK"
btnOK.Click;
end;
end.