unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
procedure Ini;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
end;
procedure TForm1.Ini;
var
i,j:byte;
begin
with stringgrid1 do begin
for i:=0 to 4 do
for j:=0 to 4 do begin
if i=0 then
cells[0,j]:=IntTostr(j)
else if j=0 then
cells[i,0]:=IntTostr(i)
else
cells[i,j]:=IntToStr(Random(100)+1);
end;
cells[5,0]:=IntTostr(5);
cells[6,0]:=IntTostr(6);
for i:=5 to 6 do
for j:=1 to 4 do
cells[ i,j]:='';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:byte;
Rect:TRect;
begin
Ini;
with stringgrid1 do
for i:=1 to Rowcount-1 do
if (strToInt(cells[1, i])+strToInt(cells[3, i]))>(strToInt(cells[2, i])+strToInt(cells[4, i])) then
cells[5,i]:= IntToStr((strToInt(cells[1, i])+strToInt(cells[3, i]))-(strToInt(cells[2, i])+strToInt(cells[4, i])))
else
cells[6,i]:= IntToStr((strToInt(cells[2, i])+strToInt(cells[4, i]))-(strToInt(cells[1, i])+strToInt(cells[3, i])));
StringGrid1DrawCell(Sender, 1, 1,rect,gdFixed);
end;
end.