1. unit Marks_u;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, StdCtrls, ComCtrls;
  8.  
  9. type
  10. TfrmMarks = class(TForm)
  11. lblName: TLabel;
  12. edtName: TEdit;
  13. btnFind: TButton;
  14. redOut: TRichEdit;
  15. lblAverage: TLabel;
  16. lblAveOut: TLabel;
  17. procedure FormActivate(Sender: TObject);
  18. procedure btnFindClick(Sender: TObject);
  19. private
  20. { Private declarations }
  21. public
  22. { Public declarations }
  23. end;
  24.  
  25. var
  26. frmMarks: TfrmMarks;
  27.  
  28. implementation
  29.  
  30. {$R *.dfm}
  31.  
  32. procedure TfrmMarks.btnFindClick(Sender: TObject);
  33. var
  34. NamesFile : TextFile;
  35. sName,sNameRead,sNameOut,sSurname,sMark,sIn : String;
  36. iPosBlank,iPosCom : Integer;
  37. bTest : Boolean;
  38. rAverage : Real;
  39. begin
  40. sName := edtName.Text;
  41.  
  42. if FileExists('Names.txt') <> True
  43. Then
  44. Begin
  45. MessageDlg('File Does not Exist',mtError,[mbOk],0);
  46. Exit;
  47. End;
  48. AssignFile(NamesFile,'Names.txt');
  49. Reset(NamesFile);
  50. bTest := False;
  51. rAverage := 0;
  52. while NOT EoF(NamesFile) do
  53. Begin
  54. ReadLn(NamesFile,sIn);
  55. iPosBlank := Pos(' ',sIn);
  56. iPosCom := Pos(',',sIn);
  57. sNameRead := Copy(sIn,1,iPosBlank-1);
  58. sNameOut := Copy(sIn,1,iPosCom-1);
  59. sMark := Copy(sIn,iPosCom+1,(Length(sIn))- ((Length(sNameOut))-2));
  60. sSurname := Copy(sIn,iPosBlank+1,Length(sIn)-iPosBlank - (Length(sMark) + 1));
  61. if (sNameRead = sName) OR (sSurname = sName) OR (sNameOut = sName)
  62. then
  63. Begin
  64. rAverage := rAverage + StrToInt(sMark);
  65. lblAveOut.Caption := FloatToStr(rAverage);
  66. bTest := True;
  67. redOut.Lines.Add(sNameOut + #9 + sMark);
  68. End;
  69. End;
  70. if bTest <> True
  71. Then
  72. Begin
  73. MessageDlg('No Results Found.' + #10 + 'Please Try a Different Name.' + #10 + 'Check that the spelling is Correct.',mtError,[mbOk],0);
  74. edtName.Clear;
  75. edtName.SetFocus;
  76. End;
  77. CloseFile(NamesFile);
  78. end;
  79.  
  80. procedure TfrmMarks.FormActivate(Sender: TObject);
  81. begin
  82. redOut.Paragraph.TabCount := 1;
  83. redOut.Paragraph.Tab[0] := 100;
  84.  
  85. redOut.SelAttributes.Style := [fsbold];
  86. redOut.Lines.Add('Name:' + #9 + 'Mark:');
  87. redOut.SelAttributes.Style := [];
  88. end;
  89.  
  90. end.
  91.