I have an assignment that I need to create a system where users log in and vote on some issue.
I have to use 2 dat files, one storing the number of votes for each option and the other storing the user names and passwords.
So far I've managed to do the first one, because it will only ever have one record which is overwritten each time, but I'm having trouble creating the file of usernames.
New names have to be created by the master user. When they press the 'OK' button, I want it to add the new username and password (from edit boxes) to the end of the dat file. At the moment it's overwriting the first record each time. I've tried 'Append' but it comes up with an error (incompatible types). Can someone give me any pointers please?
Also, when I opened the file in Notepad I can only see the username, not the password. Is this normal? (We were only taught using .txt files and I don't remember any being invisible).
Comments
:
: I have to use 2 dat files, one storing the number of votes for each option and the other storing the user names and passwords.
:
: So far I've managed to do the first one, because it will only ever have one record which is overwritten each time, but I'm having trouble creating the file of usernames.
:
: New names have to be created by the master user. When they press the 'OK' button, I want it to add the new username and password (from edit boxes) to the end of the dat file. At the moment it's overwriting the first record each time. I've tried 'Append' but it comes up with an error (incompatible types). Can someone give me any pointers please?
:
: Also, when I opened the file in Notepad I can only see the username, not the password. Is this normal? (We were only taught using .txt files and I don't remember any being invisible).
:
Append() procedure only works with textfiles. Also there are several objects, which have Append() methods. If you are using the Append() procedure within a method or a with-do statement of such an object, you need o force the correct procedure by adding the unitname before the word Append like this:
[code]
system.Append(SomeTextFile);
[/code]
You might have forgotten to save the passwords. Check your code on that, or post the relevant parts if you're unsure what's going on.
: :
: : I have to use 2 dat files, one storing the number of votes for each option and the other storing the user names and passwords.
: :
: : So far I've managed to do the first one, because it will only ever have one record which is overwritten each time, but I'm having trouble creating the file of usernames.
: :
: : New names have to be created by the master user. When they press the 'OK' button, I want it to add the new username and password (from edit boxes) to the end of the dat file. At the moment it's overwriting the first record each time. I've tried 'Append' but it comes up with an error (incompatible types). Can someone give me any pointers please?
: :
: : Also, when I opened the file in Notepad I can only see the username, not the password. Is this normal? (We were only taught using .txt files and I don't remember any being invisible).
: :
: Append() procedure only works with textfiles. Also there are several objects, which have Append() methods. If you are using the Append() procedure within a method or a with-do statement of such an object, you need o force the correct procedure by adding the unitname before the word Append like this:
: [code]
: system.Append(SomeTextFile);
: [/code]
: You might have forgotten to save the passwords. Check your code on that, or post the relevant parts if you're unsure what's going on.
:
I tried using a textfile instead but it still said incompatible types. Could I have done something elsewhere that stops it from working?
This is what I have at the moment:
[code]
procedure TSupervisorForm.FormShow(Sender: TObject);
begin
AssignFile (VoterInformation, 'Login.dat');
AssignFile (IssueInformation, 'Voting.dat');
Reset (IssueInformation);
end;
procedure TSupervisorForm.ButtonAddUserClick(Sender: TObject);
begin
Append(VoterInformation);
NewName := EditName.Text;
NewPIN := StrToInt(EditPIN.Text);
UserRec.UserName := NewName;
UserRec.UserPIN := NewPIN;
UserRec.UserVoted := False;
Write(VoterInformation, UserRec);
CloseFile(VoterInformation);
end;
[/code]
But the 'Append' bit doesn't work.
: : :
: : : I have to use 2 dat files, one storing the number of votes for each option and the other storing the user names and passwords.
: : :
: : : So far I've managed to do the first one, because it will only ever have one record which is overwritten each time, but I'm having trouble creating the file of usernames.
: : :
: : : New names have to be created by the master user. When they press the 'OK' button, I want it to add the new username and password (from edit boxes) to the end of the dat file. At the moment it's overwriting the first record each time. I've tried 'Append' but it comes up with an error (incompatible types). Can someone give me any pointers please?
: : :
: : : Also, when I opened the file in Notepad I can only see the username, not the password. Is this normal? (We were only taught using .txt files and I don't remember any being invisible).
: : :
: : Append() procedure only works with textfiles. Also there are several objects, which have Append() methods. If you are using the Append() procedure within a method or a with-do statement of such an object, you need o force the correct procedure by adding the unitname before the word Append like this:
: : [code]
: : system.Append(SomeTextFile);
: : [/code]
: : You might have forgotten to save the passwords. Check your code on that, or post the relevant parts if you're unsure what's going on.
: :
:
:
: I tried using a textfile instead but it still said incompatible types. Could I have done something elsewhere that stops it from working?
:
: This is what I have at the moment:
:
: [code]
: procedure TSupervisorForm.FormShow(Sender: TObject);
: begin
: AssignFile (VoterInformation, 'Login.dat');
: AssignFile (IssueInformation, 'Voting.dat');
: Reset (IssueInformation);
: end;
:
: procedure TSupervisorForm.ButtonAddUserClick(Sender: TObject);
: begin
: [red]system.[/red]Append(VoterInformation);
:
: NewName := EditName.Text;
: NewPIN := StrToInt(EditPIN.Text);
:
: UserRec.UserName := NewName;
: UserRec.UserPIN := NewPIN;
: UserRec.UserVoted := False;
:
: Write(VoterInformation, UserRec);
: CloseFile(VoterInformation);
: end;
: [/code]
:
: But the 'Append' bit doesn't work.
:
I mentioned this problem in my previous post. Try adding the unit in which Append() is declared. See above in red. Also if the user clicks the AddUserButton, the VoterInformation is no longed assigned to its filename, so you will get an error while adding the second user.
: : : :
: : : : I have to use 2 dat files, one storing the number of votes for each option and the other storing the user names and passwords.
: : : :
: : : : So far I've managed to do the first one, because it will only ever have one record which is overwritten each time, but I'm having trouble creating the file of usernames.
: : : :
: : : : New names have to be created by the master user. When they press the 'OK' button, I want it to add the new username and password (from edit boxes) to the end of the dat file. At the moment it's overwriting the first record each time. I've tried 'Append' but it comes up with an error (incompatible types). Can someone give me any pointers please?
: : : :
: : : : Also, when I opened the file in Notepad I can only see the username, not the password. Is this normal? (We were only taught using .txt files and I don't remember any being invisible).
: : : :
: : : Append() procedure only works with textfiles. Also there are several objects, which have Append() methods. If you are using the Append() procedure within a method or a with-do statement of such an object, you need o force the correct procedure by adding the unitname before the word Append like this:
: : : [code]
: : : system.Append(SomeTextFile);
: : : [/code]
: : : You might have forgotten to save the passwords. Check your code on that, or post the relevant parts if you're unsure what's going on.
: : :
: :
: :
: : I tried using a textfile instead but it still said incompatible types. Could I have done something elsewhere that stops it from working?
: :
: : This is what I have at the moment:
: :
: : [code]
: : procedure TSupervisorForm.FormShow(Sender: TObject);
: : begin
: : AssignFile (VoterInformation, 'Login.dat');
: : AssignFile (IssueInformation, 'Voting.dat');
: : Reset (IssueInformation);
: : end;
: :
: : procedure TSupervisorForm.ButtonAddUserClick(Sender: TObject);
: : begin
: : [red]system.[/red]Append(VoterInformation);
: :
: : NewName := EditName.Text;
: : NewPIN := StrToInt(EditPIN.Text);
: :
: : UserRec.UserName := NewName;
: : UserRec.UserPIN := NewPIN;
: : UserRec.UserVoted := False;
: :
: : Write(VoterInformation, UserRec);
: : CloseFile(VoterInformation);
: : end;
: : [/code]
: :
: : But the 'Append' bit doesn't work.
: :
: I mentioned this problem in my previous post. Try adding the unit in which Append() is declared. See above in red. Also if the user clicks the AddUserButton, the VoterInformation is no longed assigned to its filename, so you will get an error while adding the second user.
:
Thankyou it's working now :-)