Cześć, mam problem tj. program losuje mi liczby i uklada w 2 wierszową tabele ( jak na obrazku ) , po nacisnięciu guzika sprawdz ma sprawdzac która liczba ( w danej kolumnie ) jest większa .
Losowanie działa, lecz wybieranie max już nie . Proszę o jakieś wskazówki.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
Grids;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
tablica:array[0..1,0..3] of integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var kolumna,wiersz:integer;
begin
for wiersz:=0 to 1 do
begin
for kolumna:=0 to 3 do
begin
tablica[kolumna,wiersz]:=(random(5)+1);
StringGrid1.cells[kolumna,wiersz]:=IntToStr(tablica[kolumna,wiersz]);
end
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
kolumna,wiersz,max:integer;
begin
for wiersz:=0 to 1 do
begin
for kolumna:=0 to 3 do
begin
max:=0; {na początku każdego wiersza ustawiamy wartosc maks na mniejszą od dowolnej możliwej}
if (tablica[kolumna,wiersz]>=max) then {gdy jakas liczba w wierszu jest > od aktualnej wartosci max, to max przypisujemy ta liczbę}
begin
max:=tablica[kolumna,wiersz];
StringGrid2.cells[kolumna,0]:=IntToStr(max); {po przejsciu przez caly wiersz wstawiamy uzyskana max do
drugiej kolumny StringGrid2}
end;
end;
end;
end;
end.