Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Signup;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TUserInfo = Record
- Username: String[25];
- Password: String[25];
- End;
- TfrmSignup = class(TForm)
- lblEnterDetails: TLabel;
- lblUsername: TLabel;
- edtUsername: TEdit;
- lblPassword: TLabel;
- edtPassword: TEdit;
- lblPassword2: TLabel;
- edtPassword2: TEdit;
- btnSignUp: TButton;
- btnExit: TButton;
- lblPasswordMatch: TLabel;
- lblUserTaken: TLabel;
- edtTesting: TEdit;
- procedure btnExitClick(Sender: TObject);
- procedure btnSignUpClick(Sender: TObject);
- procedure edtPasswordKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure edtPassword2KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure edtUsernameKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- public
- Info : File of TUserInfo; //Record for user data
- end;
- var
- Info: File of TUserInfo;
- frmSignup: TfrmSignup;
- UsernameInput, PasswordInput : string[25];
- UserInfo: TUserInfo;
- implementation
- {$R *.dfm}
- uses Login, Main;
- procedure CheckFieldsAreComplete;
- begin
- if (frmSignup.lblPasswordMatch.Caption = 'Passwords Match') and (frmSignup.edtUsername.Text <> '') and
- (frmSignup.edtPassword.Text <> '') and (frmSignup.edtPassword2.Text <> '') and
- not(frmSignup.lblUserTaken.visible) then //Checks that all the fields are completed
- //for signup
- frmSignup.btnSignup.Enabled := True;
- end;
- procedure TfrmSignup.btnSignUpClick(Sender: TObject);
- begin
- UsernameInput := edtUsername.Text;
- PasswordInput := edtPassword.Text;
- frmSignup.visible := false;
- frmMainMenu.visible := True;
- edtUsername.Text := ''; //makes all fields empty when sign up is pressed
- edtPassword.Text := '';
- edtPassword2.Text := '';
- {$I-}
- AssignFile(Info, 'UserInfo.dat');
- reset(Info) ;
- {$I+}
- if (IOResult <> 0) then
- begin //Checks if the file exists when the user clicks the signup button. If it doesn't then recreate the file
- rewrite(Info);
- Closefile(Info);
- end;
- AssignFile(Info, 'UserInfo.dat');
- reset (Info);
- UserInfo.Username := edtUsername.Text;
- UserInfo.Password := edtPassword.Text;
- Seek(Info, Filesize(Info));
- Write(Info, UserInfo);
- Closefile(Info);
- edtTesting.Text := 'written to file';
- end;
- procedure TfrmSignup.btnExitClick(Sender: TObject);
- begin
- frmSignup.visible := false;
- frmMainMenu.visible := True; //Show main form
- end;
- procedure TfrmSignup.edtUsernameKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- var //Checks to see if the username is taken
- UserTaken: Boolean;
- begin
- UserTaken := True;
- AssignFile(Info, 'UserInfo.dat');
- reset(Info);
- while Not Eof(Info) do
- begin
- read(Info, UserInfo);
- if edtUsername.Text = UserInfo.Username then //If username entered matches one in the file then...
- begin
- lblUserTaken.visible := True; //Notify the user
- end
- else
- begin
- UserTaken := false;
- lblUserTaken.visible := false;
- end;
- if Not UserTaken then
- begin
- CheckFieldsAreComplete;
- break
- end;
- end;
- Closefile(Info)
- end;
- procedure TfrmSignup.edtPasswordKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin
- begin //Check if passwords match
- frmSignup.lblPasswordMatch.visible := True;
- if (edtPassword.Text <> edtPassword2.Text) then
- frmSignup.lblPasswordMatch.Caption := 'Passwords do not match';
- if (edtPassword.Text <> edtPassword2.Text) then
- frmSignup.lblPasswordMatch.Color := clgreen
- else
- begin
- lblPasswordMatch.Caption := 'Passwords Match';
- lblPasswordMatch.Color := clRed
- end;
- CheckFieldsAreComplete;
- end;
- end;
- procedure TfrmSignup.edtPassword2KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin //Check if passwords match
- lblPasswordMatch.visible := True;
- if edtPassword.Text <> edtPassword2.Text then
- lblPasswordMatch.Caption := 'Passwords do not match';
- if edtPassword.Text <> edtPassword2.Text then
- lblPasswordMatch.Color := clRed
- else
- begin
- lblPasswordMatch.Caption := 'Password Match';
- lblPasswordMatch.Font.Color := clgreen;
- end;
- CheckFieldsAreComplete;
- end;
- procedure TfrmSignup.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- frmSignUp.Visible := False;
- frmMainMenu.Visible := true;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement