unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons, ComCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
StringGrid1: TStringGrid;
GroupBox2: TGroupBox;
StringGrid2: TStringGrid;
Button1: TSpeedButton;
GroupBox3: TGroupBox;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
UpDown1: TUpDown;
UpDown2: TUpDown;
GroupBox4: TGroupBox;
Label1: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label11: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit1Change(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
col,row: integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i,j:integer;
begin
StringGrid1.Cells[0,0]:= 'Команда';
StringGrid1.Cells[0,1]:= 'Ливерпуль';
StringGrid1.Cells[1,0]:= 'Ливерпуль';
StringGrid1.Cells[0,2]:= 'Челси';
StringGrid1.Cells[2,0]:= 'Челси';
StringGrid1.Cells[0,3]:= 'Интер';
StringGrid1.Cells[3,0]:= 'Интер';
StringGrid1.Cells[0,4]:= 'Ювентус';
StringGrid1.Cells[4,0]:= 'Ювентус';
StringGrid1.Cells[0,5]:= 'Севилья';
StringGrid1.Cells[5,0]:= 'Севилья';
StringGrid1.Cells[0,6]:= 'Барселона';
StringGrid1.Cells[6,0]:= 'Барселона';
StringGrid1.Cells[0,7]:= 'Мд.Реал';
StringGrid1.Cells[7,0]:= 'Мд.Реал';
StringGrid1.Cells[0,8]:= 'Манчестер';
StringGrid1.Cells[8,0]:= 'Манчестер';
StringGrid1.Cells[0,9]:= 'Бавария';
StringGrid1.Cells[9,0]:= 'Бавария';
StringGrid1.Cells[0,10]:= 'Рекинг';
StringGrid1.Cells[10,0]:= 'Рекинг';
for i:=1 to 10 do
for j:=1 to 10 do
if i <> j then
StringGrid1.Cells[i,j]:= '0 : 0'
else
StringGrid1.Cells[i,j]:= 'XXX';
StringGrid2.Cells[0,0]:= 'Команда';
StringGrid2.Cells[1,0]:= 'Очки';
StringGrid2.Cells[2,0]:= 'Голы';
StringGrid2.Cells[3,0]:= 'Пропущенные мячи';
StringGrid2.ColWidths[0]:= 150;
StringGrid1.ColWidths[0]:= 68;
StringGrid1.Cells[0,0]:= 'Команда';
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j,a,b,o,gl,pm,gl1,rz,n,m:integer;
s:string;
begin
StringGrid2.RowCount:= StringGrid1.RowCount;
n:=1; m:=1; gl1:= 0; rz:= 0;
for i:=1 to 10 do
begin
StringGrid2.Cells[0,i]:= StringGrid1.Cells[0,i];
o:= 0;
gl:= 0;
pm:= 0;
for j:=1 to 10 do
begin
if i <> j then
begin
s:= StringGrid1.Cells[j,i];
a:= StrToInt(copy(s,0,pos(':',s) - 2));
b:= StrToInt(copy(s,pos(':',s) + 2,length(s) - pos(':',s)));
gl:= gl + a;
pm:= pm + b;
if a > b then
o:= o + 2
else if a = b then
o:= o + 1;
end;
end;
StringGrid2.Cells[1,i]:= IntToStr(o);
StringGrid2.Cells[2,i]:= IntToStr(gl);
StringGrid2.Cells[3,i]:= IntToStr(pm);
if gl1 < gl then begin gl1:= gl; n:= i; end;
if rz < gl - pm then begin rz:= gl - pm; m:= i; end;
end;
Label7.Caption:= StringGrid2.Cells[0,n];
Label8.Caption:= StringGrid2.Cells[0,m];
for i:=1 to 10 do
begin
j:= i;
a:=StrToInt(StringGrid2.Cells[1,i]);
b:= i;
while j <= 10 do
begin
if a < StrToInt(StringGrid2.Cells[1,j]) then
begin
a:= StrToInt(StringGrid2.Cells[1,j]);
b:= j;
end;
j:= j + 1;
end;
if b <> i then
begin
s:= StringGrid2.Cells[0,i];
StringGrid2.Cells[0,i]:= StringGrid2.Cells[0,b];
StringGrid2.Cells[0,b]:= s;
s:= StringGrid2.Cells[1,i];
StringGrid2.Cells[1,i]:= StringGrid2.Cells[1,b];
StringGrid2.Cells[1,b]:= s;
s:= StringGrid2.Cells[2,i];
StringGrid2.Cells[2,i]:= StringGrid2.Cells[2,b];
StringGrid2.Cells[2,b]:= s;
s:= StringGrid2.Cells[3,i];
StringGrid2.Cells[3,i]:= StringGrid2.Cells[3,b];
StringGrid2.Cells[3,b]:= s;
end;
end;
Label5.Caption:= StringGrid2.Cells[0,1];
GroupBox4.Visible:= True;
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var s:string;
begin
row:= ARow; col:= ACol;
s:= StringGrid1.Cells[col,row];
Label2.Caption:= StringGrid1.Cells[0,ARow];
Label3.Caption:= StringGrid1.Cells[ACol,0];
Edit1.Text:= copy(s,1,length(s) - pos(':',s) - 1);
Edit2.Text:= copy(s,pos(':',s)+2,length(s) - pos(':',s));
if ARow = ACol then
begin
Edit1.Enabled:= False;
Edit2.Enabled:= False;
end
else
begin
Edit1.Enabled:= True;
Edit2.Enabled:= True;
end;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if ((key<#48)or(key>#57))and(key<>#8)then
key:=#0;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
if (Edit1.Text <> '') and (Edit1.Text <> '')and(col<>row) then
begin
StringGrid1.Cells[col,row]:= Edit1.Text + ' : ' + Edit2.Text;
StringGrid1.Cells[row,col]:= Edit2.Text + ' : ' + Edit1.Text;
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if StringGrid1.Cells[Acol,Arow] = 'XXX' then
begin
StringGrid1.canvas.Font.Color:= clRed;
StringGrid1.canvas.Font.Color:= clRed;
StringGrid1.Canvas.TextOut(rect.Left+3,Rect.Top+3,StringGrid1.Cells[ACol,ARow]);
end;
end;
end.