Delphi beginners

Moderators: netgert
Number of threads: 358
Number of posts: 982

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Adding to a dat file Posted by OllieV on 14 Apr 2004 at 5:39 AM
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).
Report
Re: Adding to a dat file Posted by zibadian on 14 Apr 2004 at 10:12 AM
: 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).
:
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:
  system.Append(SomeTextFile);

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.
Report
Re: Adding to a dat file Posted by OllieV on 15 Apr 2004 at 8:34 AM
: : 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).
: :
: 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:
:
:   system.Append(SomeTextFile);
: 

: 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:

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;


But the 'Append' bit doesn't work.
Report
Re: Adding to a dat file Posted by zibadian on 16 Apr 2004 at 12:57 AM
: : : 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).
: : :
: : 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:
: :
: :   system.Append(SomeTextFile);
: : 

: : 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:
:
:
: procedure TSupervisorForm.FormShow(Sender: TObject);
: begin
:    AssignFile (VoterInformation, 'Login.dat');
:    AssignFile (IssueInformation, 'Voting.dat');
:    Reset (IssueInformation);
: end;
: 
: procedure TSupervisorForm.ButtonAddUserClick(Sender: TObject);
: begin
:         system.Append(VoterInformation);
: 
:         NewName := EditName.Text;
:         NewPIN := StrToInt(EditPIN.Text);
: 
:         UserRec.UserName := NewName;
:         UserRec.UserPIN := NewPIN;
:         UserRec.UserVoted := False;
: 
:         Write(VoterInformation, UserRec);
:         CloseFile(VoterInformation);
: end;
: 

:
: 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.
Report
Re: Adding to a dat file Posted by OllieV on 16 Apr 2004 at 8:32 AM
: : : : 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).
: : : :
: : : 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:
: : :
: : :   system.Append(SomeTextFile);
: : : 

: : : 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:
: :
: :
: : procedure TSupervisorForm.FormShow(Sender: TObject);
: : begin
: :    AssignFile (VoterInformation, 'Login.dat');
: :    AssignFile (IssueInformation, 'Voting.dat');
: :    Reset (IssueInformation);
: : end;
: : 
: : procedure TSupervisorForm.ButtonAddUserClick(Sender: TObject);
: : begin
: :         system.Append(VoterInformation);
: : 
: :         NewName := EditName.Text;
: :         NewPIN := StrToInt(EditPIN.Text);
: : 
: :         UserRec.UserName := NewName;
: :         UserRec.UserPIN := NewPIN;
: :         UserRec.UserVoted := False;
: : 
: :         Write(VoterInformation, UserRec);
: :         CloseFile(VoterInformation);
: : end;
: : 

: :
: : 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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.