Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit_AddLogin;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.StdCtrls, Vcl.Controls, Vcl.ExtCtrls, Vcl.Graphics,
- Vcl.Forms, Vcl.Dialogs;
- type
- TfrmAddlogin = class(TForm)
- lbledtNew_username: TLabeledEdit;
- lbledtNew_Password: TLabeledEdit;
- btnSubmit: TButton;
- btnExit: TButton;
- procedure btnSubmitClick(Sender: TObject);
- //procedure btnShowClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure btnExitClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmAddlogin: TfrmAddlogin;
- implementation
- uses
- Unit_Login,Unit_TeacherMenu; //Allows this form to use the login unit
- {$R *.dfm}
- type
- TUsername = record
- Username :string[20];
- end;
- type
- TPassword = record
- Password:string[20];
- end;
- Var
- UsernameFile : File of TUsername; //File which will store usernames
- PasswordFile : File of TPassword; //FIle which will store Password
- New_username : array [1..1000] of Tusername;
- New_Password : array [1..1000] of TPassword;
- count,counter,number : integer; //Variables used when reading from file and writting to array
- procedure TfrmAddlogin.btnExitClick(Sender: TObject);
- begin
- Close;
- end;
- procedure TfrmAddlogin.btnSubmitClick(Sender: TObject);
- var
- I: integer;
- begin
- // To check username file
- AssignFile(Usernamefile,'loginsave.dat');
- reset(UsernameFile);
- count := 0;
- while not Eof(Usernamefile) do
- begin
- count := count + 1;
- Read(Usernamefile,New_username[Count]); //reads all the usernames that first stored in the file
- end;
- Closefile(Usernamefile);
- //To create usernames
- AssignFile(Usernamefile,'loginsave.dat');
- reset(Usernamefile);
- count := count + 1; //increments the pointer to store in the array without overwriting any data
- New_Username[count].Username := lbledtNew_Username.text;
- i := 0;
- //The following code is a presence check. This ensure that the password field is not left blank
- if (New_Username[count].Username = lbledtNew_Username.text) and (lbledtNew_Password.text = '') then
- {If any of the fields are blanl then the user will be notifed and the form will close}
- begin
- Showmessage('Error enter a Password');
- close;
- FrmteacherMenu.Show;
- end;
- if (lbledtNew_Username.text <> '') and (lbledtNew_Password.text <> '') then {the code will not run
- if the any of the fields are blank}
- begin
- for number := 1 to count do
- begin
- I := I + 1;
- Write(UsernameFile,New_username[I]); //stores the usernames into the array
- end;
- CloseFile(Usernamefile);
- end;
- // to check password file
- AssignFile(Passwordfile,'Password.dat');
- reset(PasswordFile);
- count := 0;
- while not Eof(Passwordfile) do
- begin
- count := count + 1;
- Read(Passwordfile,New_Password[Count]); //reads all the usernames that first stored in the file
- end;
- Closefile(Passwordfile);
- //TO cretae Passwords
- AssignFile(Passwordfile,'Password.dat');
- reset(Passwordfile);
- count := count + 1; //increments the pointer to store in the array without overwriting any data
- New_Password[count].Password := lbledtNew_Password.text;
- //The following code is a presence check. This ensure that the Username field is not left blank
- if (lbledtNew_Username.text = '') and (New_Password[count].Password = lbledtNew_Password.text) then
- begin
- Showmessage('Error enter a Username');
- close;
- FrmteacherMenu.Show;
- end;
- if (lbledtNew_Username.text <> '') and (lbledtNew_Password.text <> '') then
- begin
- count := count + 1; //increments the pointer to store in the array without overwriting any data
- New_Password[count].Password := lbledtNew_Password.text;
- i := 0;
- for number := 1 to count do
- begin
- I := I + 1;
- Write(PasswordFile,New_Password[I]); //stores the Password into the array
- end;
- end;
- CloseFile(Passwordfile);
- end;
- procedure TfrmAddlogin.FormCreate(Sender: TObject);
- begin
- lbledtNew_Password.text := '';
- lbledtNew_Username.Text := '';
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement