unit Forms.MainForm;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls,
Vcl.Buttons;
type
TMainForm =
class( TForm )
PasswordLabel: TLabel;
Num0Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num1Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num2Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num3Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num4Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num5Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num6Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num7Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num8Button: TSpeedButton;
{OnClick -> NumButtonClick}
Num9Button: TSpeedButton;
{OnClick -> NumButtonClick}
ClearButton: TSpeedButton;
{OnClick -> ClearButtonClick}
BackspaceButton: TSpeedButton;
{OnClick -> BackspaceButtonCLick}
Timer1: TTimer;
procedure Timer1Timer( Sender: TObject );
procedure FormShow( Sender: TObject );
procedure NumButtonClick( Sender: TObject );
procedure BackspaceButtonClick( Sender: TObject );
procedure ClearButtonClick( Sender: TObject );
private
FPassword:
string;
procedure AddKey(
const AChar: Char );
procedure ClearPassword;
procedure PresentPassword;
public
property Password:
string read FPassword;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses
System.StrUtils;
{ TMainForm }
procedure TMainForm.AddKey(
const AChar: Char );
begin
case AChar
of
#8:
begin
if Length( FPassword ) > 0
then
begin
SetLength( FPassword, Length( FPassword ) - 1 );
PasswordLabel.Caption := DupeString( '
*', Length( FPassword ) );
end;
end;
'
0' .. '
9':
begin
Timer1.Enabled := False;
PasswordLabel.Caption := DupeString( '
*', Length( FPassword ) ) + AChar;
FPassword := FPassword + AChar;
Timer1.Enabled := True;
end;
end;
end;
procedure TMainForm.BackspaceButtonClick( Sender: TObject );
begin
AddKey( #8 );
end;
procedure TMainForm.ClearButtonClick( Sender: TObject );
begin
ClearPassword;
end;
procedure TMainForm.ClearPassword;
begin
FPassword := '
';
PasswordLabel.Caption := '
';
end;
procedure TMainForm.FormShow( Sender: TObject );
begin
PresentPassword;
end;
procedure TMainForm.NumButtonClick( Sender: TObject );
var
Button: TComponent
absolute Sender;
begin
AddKey( Button.
Name[ 4 ] );
// Ich bin halt faul ;o)
end;
procedure TMainForm.PresentPassword;
begin
PasswordLabel.Caption := DupeString( '
*', Length( FPassword ) );
end;
procedure TMainForm.Timer1Timer( Sender: TObject );
begin
TTimer( Sender ).Enabled := False;
PresentPassword;
end;
end.