Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Results;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TForm1 = class(TForm)
- Memo1: TMemo;
- Label1: TLabel; // Labels for display
- Label2: TLabel;
- procedure FormActivate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Userfile: textfile;
- TextString, Username: string;
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.FormActivate(Sender: TObject);
- var
- MemoLineAdd: string;
- done, found: boolean;
- begin
- Memo1.Lines.Clear;
- Memo1.Lines.Append(' '); // clearing and resetting file
- Memo1.Lines.Append(' ');
- Memo1.Lines.Append(' ');
- Memo1.Lines.Append(' ');
- AssignFile(Userfile, 'TempUser.txt'); // Open the user using file
- Reset(Userfile);
- readln(Userfile, Username);
- Closefile(Userfile);
- MemoLineAdd := 'Results For ' + Username;
- Memo1.Lines.Append(MemoLineAdd);
- AssignFile(Userfile, 'UserData.txt'); // Open the user using file
- Reset(Userfile);
- readln(Userfile, TextString);
- done := false;
- found := false;
- while (done = false) do
- begin
- if (TextString = Username) then
- begin
- found := true;
- readln(Userfile, TextString);
- while (strtoint(TextString) < 100) do
- // JUSTIFICATION: Usernames and scores need to be differentiated between, since they are both stored in the same file. So since since student numbers are 6 digit figures, and scores 1-2 digits, scores keep being read till a number over 100 is met i.e. the next student number stored.
- begin
- Memo1.Lines.Append(TextString);
- readln(Userfile, TextString);
- if EOF(Userfile) then
- begin
- TextString := '100'; // setting limit
- end;
- end;
- done := true;
- end
- else
- begin
- readln(Userfile, TextString);
- if EOF(Userfile) then // if scores for the current username aren't found
- begin
- if (found = false) then
- begin
- MemoLineAdd := 'No Results Found';
- // display 'no results found' under username
- Memo1.Lines.Append(MemoLineAdd);
- end;
- done := true;
- end;
- end;
- end;
- Closefile(Userfile);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement