Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit ScoresForm;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.Imaging.jpeg,
- Vcl.ExtCtrls, Vcl.StdCtrls;
- type
- TUsers = record
- strName: ShortString;
- intScore: Integer;
- end;
- type
- TScoresFrm = class(TForm)
- stgrUserScores: TStringGrid;
- imgFonScores: TImage;
- lblScore: TLabel;
- procedure FormCreate(Sender: TObject);
- private
- procedure Sort;
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- ScoresFrm: TScoresFrm;
- implementation
- {$R *.dfm}
- procedure TScoresFrm.Sort;
- var
- i, j: Integer;
- strHelp: string;
- begin
- for i := 1 to stgrUserScores.RowCount - 1 do
- begin
- for j := 1 to stgrUserScores.RowCount - i - 1 do
- begin
- if StrToInt(stgrUserScores.Cells[1, j]) < StrToInt(stgrUserScores.Cells[1, j + 1]) then
- begin
- strHelp := stgrUserScores.Cells[1, j];
- stgrUserScores.Cells[1, j] := stgrUserScores.Cells[1, j + 1];
- stgrUserScores.Cells[1, j + 1] := strHelp;
- strHelp := stgrUserScores.Cells[0, j];
- stgrUserScores.Cells[0, j] := stgrUserScores.Cells[0, j + 1];
- stgrUserScores.Cells[0, j + 1] := strHelp;
- end;
- end;
- end;
- end;
- procedure TScoresFrm.FormCreate(Sender: TObject);
- const
- strNameOfFile = 'TypedFile.dat';
- var
- usrFile: File of TUsers;
- usrArray: array of TUsers;
- i: Integer;
- begin
- AssignFile(usrFile, strNameOfFile);
- if FileExists(strNameOfFile) then
- Reset(usrFile)
- else
- Rewrite(usrFile);
- SetLength(usrArray, FileSize(usrFile));
- stgrUserScores.Cells[0,0] := 'Users';
- stgrUserScores.Cells[1,0] := 'Score';
- stgrUserScores.RowCount := FileSize(usrFile) + 1;
- for i := 0 to FileSize(usrFile) - 1 do
- begin
- Read(usrFile, usrArray[i]);
- stgrUserScores.Cells[0, i + 1] := usrArray[i].strName;
- stgrUserScores.Cells[1, i + 1] := IntToStr(usrArray[i].intScore);
- end;
- Sort();
- CloseFile(usrFile);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement