📄 table.pas
字号:
//排行榜单元 table.pas
//BY Lishun,1999,all rights reserved
unit table;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, StdCtrls, Buttons, all, ExtCtrls;
type
Ttablefrm = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Panel1: TPanel;
grid: TStringGrid;
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure gridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
tablefrm: Ttablefrm;
implementation
uses main;
{$R *.DFM}
procedure Ttablefrm.BitBtn2Click(Sender: TObject);
var
i: integer;
myfile: Tfilestream;
begin
myfile := Tfilestream.Create(path + 'chessrec.lis', fmCreate);
for i := 1 to 10 do begin
myfile.WriteBuffer(dat[i].name, sizeof(dat[i].name));
myfile.WriteBuffer(dat[i].level, 1);
myfile.WriteBuffer(dat[i].score, sizeof(dat[i].score));
end;
myfile.Free;
close;
end;
procedure Ttablefrm.BitBtn1Click(Sender: TObject);
var i: integer;
begin
if MessageDlg('还原为默认值将删除已有的积分榜,' + #13 + '要继续吗?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
for i := 0 to 3 do begin
dat[10 - i].name := 'li shun';
dat[10 - i].level := 1;
dat[10 - i].score := 30 + i * 10;
end;
for i := 4 to 7 do begin
dat[10 - i].name := 'li shun';
dat[10 - i].level := 2;
dat[10 - i].score := 30 + i * 20;
end;
for i := 7 to 9 do begin
dat[10 - i].name := 'li shun';
dat[10 - i].level := 3;
dat[10 - i].score := i * 30;
end;
with grid do begin
for i := 1 to 10 do begin
cells[1, i] := dat[i].name;
case dat[i].level of
1: cells[2, i] := '一级';
2: cells[2, i] := '二级';
3: cells[2, i] := '三级';
4: cells[2, i] := '四级';
5: cells[2, i] := '五级';
6: cells[2, i] := '六级';
7: cells[2, i] := '七级';
end;
cells[3, i] := inttostr(dat[i].score);
if (dat[i].score <= 65) then cells[4, i] := '学员'
else if (dat[i].score <= 80) then cells[4, i] := '下士'
else if (dat[i].score <= 95) then cells[4, i] := '中士'
else if (dat[i].score <= 110) then cells[4, i] := '上士'
else if (dat[i].score <= 130) then cells[4, i] := '少尉'
else if (dat[i].score <= 150) then cells[4, i] := '中尉'
else if (dat[i].score <= 170) then cells[4, i] := '上尉'
else if (dat[i].score <= 190) then cells[4, i] := '少校'
else if (dat[i].score <= 215) then cells[4, i] := '中校'
else if (dat[i].score <= 240) then cells[4, i] := '上校'
else if (dat[i].score <= 265) then cells[4, i] := '少将'
else if (dat[i].score <= 290) then cells[4, i] := '中将'
else if (dat[i].score <= 320) then cells[4, i] := '上将'
else cells[4, i] := '元首';
end;
end;
end;
end;
procedure Ttablefrm.BitBtn3Click(Sender: TObject);
begin
close;
end;
procedure Ttablefrm.FormActivate(Sender: TObject);
var
i: integer;
myfile: Tfilestream;
begin
if not fileexists(path + 'chessrec.lis') then
begin
for i := 0 to 3 do begin
dat[10 - i].name := 'li shun';
dat[10 - i].level := 1;
dat[10 - i].score := 30 + i * 10;
end;
for i := 4 to 7 do begin
dat[10 - i].name := 'li shun';
dat[10 - i].level := 2;
dat[10 - i].score := 30 + i * 20;
end;
for i := 7 to 9 do begin
dat[10 - i].name := 'li shun';
dat[10 - i].level := 3;
dat[10 - i].score := i * 30;
end;
end
else begin
myfile := Tfilestream.Create(path + 'chessrec.lis', fmOpenRead);
for i := 1 to 10 do begin
myfile.ReadBuffer(dat[i].name, sizeof(dat[i].name));
myfile.ReadBuffer(dat[i].level, 1);
myfile.ReadBuffer(dat[i].score, sizeof(dat[i].score));
end;
myfile.Free;
end;
with grid do
begin
cells[1, 0] := '姓名';
cells[2, 0] := '级别';
cells[3, 0] := '得分';
cells[4, 0] := '军衔';
for i := 1 to 10 do begin
cells[0, i] := '';
cells[1, i] := dat[i].name;
case dat[i].level of
1: cells[2, i] := '一级';
2: cells[2, i] := '二级';
3: cells[2, i] := '三级';
4: cells[2, i] := '四级';
5: cells[2, i] := '五级';
6: cells[2, i] := '六级';
7: cells[2, i] := '七级';
end;
cells[3, i] := inttostr(dat[i].score);
if (dat[i].score <= 65) then cells[4, i] := '学员'
else if (dat[i].score <= 80) then cells[4, i] := '下士'
else if (dat[i].score <= 95) then cells[4, i] := '中士'
else if (dat[i].score <= 110) then cells[4, i] := '上士'
else if (dat[i].score <= 130) then cells[4, i] := '少尉'
else if (dat[i].score <= 150) then cells[4, i] := '中尉'
else if (dat[i].score <= 170) then cells[4, i] := '上尉'
else if (dat[i].score <= 190) then cells[4, i] := '少校'
else if (dat[i].score <= 215) then cells[4, i] := '中校'
else if (dat[i].score <= 240) then cells[4, i] := '上校'
else if (dat[i].score <= 265) then cells[4, i] := '少将'
else if (dat[i].score <= 290) then cells[4, i] := '中将'
else if (dat[i].score <= 320) then cells[4, i] := '上将'
else cells[4, i] := '元首';
end;
for i := 1 to 10 do cells[0, i] := '·' + inttostr(i);
if thisrec <> 0 then
begin
cells[0, thisrec] := '★' + inttostr(thisrec);
end;
end;
if thisrec <> 0 then grid.Row := thisrec;
end;
procedure Ttablefrm.gridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if odd(arow) then grid.Canvas.Brush.Color:=clred;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -