1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
unit DBLogDlg;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, ButtonPanel, DB;
type
{ TLoginDialog }
TLoginDialog = class(TForm)
protected
lDatabaseName: TLabel;
lDatabase: TLabel;
lUserName: TLabel;
lPassword: TLabel;
eUserName: TEdit;
ePassword: TEdit;
BtnPanel: TButtonPanel;
public
constructor Create(TheOwner: TComponent); override;
end;
function LoginDialogEx(const ADatabaseName: string; var AUserName, APassword: string;
UserNameReadOnly: Boolean=False): Boolean;
resourcestring
rsDBLogDlgCaption = 'Database Login';
rsDBLogDlgDatabase = 'Database';
rsDBLogDlgUserName = '&User Name';
rsDBLogDlgPassword = '&Password';
rsDBLogDlgLogin = '&Login';
implementation
{ TLoginDialog }
constructor TLoginDialog.Create(TheOwner: TComponent);
begin
inherited CreateNew(TheOwner, 0);
Caption := rsDBLogDlgCaption;
Position := poScreenCenter;
AutoSize := True;
BorderStyle := bsDialog;
ChildSizing.LeftRightSpacing := Scale96ToForm(16);
ChildSizing.TopBottomSpacing := Scale96ToForm(10);
lDatabase := TLabel.Create(Self);
lDatabase.Parent := Self;
lDatabase.Caption := rsDBLogDlgDatabase;
lDatabaseName := TLabel.Create(Self);
lDatabaseName.Parent := Self;
lDatabaseName.AnchorSide[akTop].Control := lDatabase;
lDatabaseName.AnchorSide[akTop].Side := asrCenter;
lDatabaseName.AnchorSide[akLeft].Control := lDatabase;
lDatabaseName.AnchorSide[akLeft].Side := asrLeft;
lDatabaseName.BorderSpacing.Left := Scale96ToForm(80);
lUserName := TLabel.Create(Self);
lUserName.Parent := Self;
lUserName.Caption := rsDBLogDlgUserName;
lUserName.AnchorSide[akTop].Control := lDatabase;
lUserName.AnchorSide[akTop].Side := asrBottom;
lUserName.BorderSpacing.Top := Scale96ToForm(14);
eUserName := TEdit.Create(Self);
eUserName.Parent := Self;
eUserName.Width := Scale96ToForm(164);
eUserName.AnchorSide[akTop].Control := lUserName;
eUserName.AnchorSide[akTop].Side := asrCenter;
eUserName.AnchorSide[akLeft].Control := lUserName;
eUserName.AnchorSide[akLeft].Side := asrLeft;
eUserName.Anchors := [akTop, akLeft];
eUserName.BorderSpacing.Left := lDatabaseName.BorderSpacing.Left;
lUserName.FocusControl := eUserName;
lPassword := TLabel.Create(Self);
lPassword.Parent := Self;
lPassword.Caption := rsDBLogDlgPassword;
lPassword.AnchorSide[akTop].Control := lUserName;
lPassword.AnchorSide[akTop].Side := asrBottom;
lPassword.BorderSpacing.Top := Scale96ToForm(12);
ePassword := TEdit.Create(Self);
ePassword.Parent := Self;
ePassword.Width := eUserName.Width;
ePassword.PasswordChar := '*';
ePassword.AnchorSide[akTop].Control := lPassword;
ePassword.AnchorSide[akTop].Side := asrCenter;
ePassword.AnchorSide[akLeft].Control := lPassword;
ePassword.AnchorSide[akLeft].Side := asrLeft;
ePassword.Anchors := [akTop, akLeft];
ePassword.BorderSpacing.Left := lDatabaseName.BorderSpacing.Left;
lPassword.FocusControl := ePassword;
BtnPanel := TButtonPanel.Create(Self);
BtnPanel.Parent := Self;
BtnPanel.ShowBevel:= False;
BtnPanel.ShowButtons := [pbOK, pbCancel];
BtnPanel.OKButton.Caption := rsDBLogDlgLogin;
BtnPanel.AnchorSide[akTop].Control := ePassword;
BtnPanel.AnchorSide[akTop].Side := asrBottom;
BtnPanel.AnchorSide[akRight].Control := ePassword;
BtnPanel.AnchorSide[akRight].Side := asrRight;
BtnPanel.Anchors := [akTop, akRight];
BtnPanel.BorderSpacing.Top := Scale96ToForm(10);
end;
function LoginDialogEx(const ADatabaseName: string; var AUserName, APassword: string;
UserNameReadOnly: Boolean=False): Boolean;
var
F: TLoginDialog;
begin
F := TLoginDialog.Create(nil);
try
F.lDatabaseName.Caption := ADatabaseName;
F.eUserName.Text := AUserName;
F.ePassword.Text := APassword;
if UserNameReadOnly then
begin
F.eUserName.ReadOnly := True;
F.ActiveControl := F.ePassword;
end;
Result := F.ShowModal = mrOK;
if Result then
begin
AUserName := F.eUserName.Text;
APassword := F.ePassword.Text;
end;
finally
F.Free;
end;
end;
initialization
if not Assigned(LoginDialogExProc) then
LoginDialogExProc := @LoginDialogEx;
end.
|